home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / ply15doc.zip / POLYRAY.DOC < prev    next >
Text File  |  1992-11-08  |  191KB  |  4,828 lines

  1.  
  2.                                                                            
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.                                Polyray v1.5
  27.                     (c) 1991, 1992 Alexander R. Enzmann
  28.                              8 November 1992
  29.                             All Rights Reserved
  30.  
  31.  
  32.  
  33.           Table of contents
  34.  
  35.           1 Introduction & Shareware Information                           1
  36.           1.0 Installation                                                 1
  37.           1.1 Origin and Credits                                           2
  38.           1.2 Useful Tools                                                 3
  39.           1.3 Contents of This Document                                    3
  40.           1.4 Quick demo     (You really should read this section)         4
  41.           1.5 Command Line Options                                         6
  42.           1.6 Initialization File                                          8
  43.           1.7 Rendering Options                                            9
  44.           1.7.1 Raytracing                                                 9
  45.           1.7.1.1 Antialiasing                                             9
  46.           1.7.1.2 Dithering                                               11
  47.           1.7.1.3 Bounding Slabs                                          11
  48.           1.7.1.4 Shading Quality Flags                                   12
  49.           1.7.2 Scan Conversion                                           13
  50.           1.7.3 Wireframe                                                 14
  51.           2  Detailed Description of the Polyray Input Format             14
  52.           2.1 Expressions                                                 15
  53.           2.1.1 Numeric expressions                                       15
  54.           2.1.2 Vector Expressions                                        16
  55.           2.1.3 Array Expressions                                         17
  56.           2.1.4 Conditional Expressions                                   19
  57.           2.1.5 Run-Time expressions                                      20
  58.           2.1.6 Named Expressions                                         20
  59.           2.2 Definition of the viewpoint                                 21
  60.           2.3 Objects/Surfaces                                            23
  61.           2.3.1 Object Modifiers                                          25
  62.           2.3.1.1 Position and Orientation Modifiers                      25
  63.           2.3.1.1.1 Translation                                           25
  64.           2.3.1.1.2 Rotation                                              25
  65.           2.3.1.1.3 Scaling                                               26
  66.           2.3.1.1.4 Shear                                                 26
  67.           2.3.1.2 Bounding Boxes                                          26
  68.           2.3.1.3 Subdivision of Primitives                               27
  69.           2.3.1.4 Shading Flags                                           28
  70.           2.3.2 Primitives                                                29
  71.           2.3.2.1 Bezier patch                                            30
  72.           2.3.2.2 Blob                                                    31
  73.           2.3.2.3 Box                                                     32
  74.           2.3.2.4 Cone                                                    33
  75.           2.3.2.5 Cylinder                                                33
  76.           2.3.2.6 Disc                                                    33
  77.           2.3.2.7 Implicit function                                       34
  78.           2.3.2.8 Height Field                                            35
  79.           2.3.2.8.1 File Based Height Fields                              35
  80.           2.3.2.8.1.1 8 Bit Format                                        36
  81.           2.3.2.8.1.2 16 Bit Format                                       36
  82.           2.3.2.8.1.3 24 Bit Format                                       37
  83.           2.3.2.8.2 Implicit Height Fields                                37
  84.  
  85.  
  86.  
  87.  
  88.           2.3.2.9 Lathe Surface                                           38
  89.           2.3.2.10 Parabola                                               39
  90.           2.3.2.11 Polygon                                                40
  91.           2.3.2.12 Polynomial Function                                    40
  92.           2.3.2.13 Sphere                                                 42
  93.           2.3.2.14 Sweep Surface                                          42
  94.           2.3.2.15 Torus                                                  43
  95.           2.3.2.16 Triangular patch                                       44
  96.           2.3.3 Constructive Solid Geometry (CSG)                         44
  97.           2.3.4 Gridded Objects                                           46
  98.           2.3.5 Bounding Slabs                                            47
  99.           2.4 Color and Lighting                                          47
  100.           2.4.1 Light Sources                                             47
  101.           2.4.1.1 Positional Lights                                       48
  102.           2.4.1.2 Spot Lights                                             48
  103.           2.4.1.3 Textured Lights                                         49
  104.           2.4.2 Background Color                                          49
  105.           2.4.3 Textures                                                  50
  106.           2.4.3.1 Procedural Textures                                     50
  107.           2.4.3.1.1 Standard Shading Model                                50
  108.           2.4.3.1.1.1 Ambient Light                                       51
  109.           2.4.3.1.1.2 Diffuse Light                                       52
  110.           2.4.3.1.1.3 Specular Highlights                                 52
  111.           2.4.3.1.1.4 Reflected Light                                     52
  112.           2.4.3.1.1.5 Transmitted Light                                   53
  113.           2.4.3.1.1.6 Microfacet Distribution                             53
  114.           2.4.3.1.2 Checker Texture                                       54
  115.           2.4.3.1.3 Hexagon Texture                                       55
  116.           2.4.3.1.4 Noise Surface                                         55
  117.       2.4.3.1.5 Layered Textures                                      58
  118.           2.4.3.2 Functional Textures                                     60
  119.           2.4.3.2.1 Image maps                                            61
  120.           2.5 Comments                                                    63
  121.           2.6 Animation support                                           63
  122.           2.7 Conditional processing                                      63
  123.           2.8 Include files                                               65
  124.           2.9 File flush                                                  65
  125.           3 File Formats                                                  65
  126.           3.1 Output files                                                65
  127.           4 Algorithms                                                    66
  128.           4.1 Processing polynomial expressions                           66
  129.           4.1.1 Example equation representation                           66
  130.           4.1.2 Allowed Formula Syntax                                    67
  131.           4.1.3 Rules for processing formulas                             67
  132.           4.2 Processing of arbitrary functional surfaces                 68
  133.           4.2.1 Spherical coordinates                                     68
  134.           4.3 Three dimensional noise generation                          69
  135.           4.4 Marching Cubes                                              70
  136.  
  137.  
  138.  
  139.  
  140.           5 Outstanding issues                                            71
  141.           5.1 To do list                                                  71
  142.           5.2 Known Bugs                                                  71
  143.           6 Revision History                                              72
  144.           7 Bibliography                                                  77
  145.           8 Sample files                                                  77
  146.           9 Polyray grammar                                               78
  147.  
  148.  
  149.                                                                               1
  150.  
  151.  
  152.           1 Introduction & Shareware Information
  153.  
  154.           The program "Polyray" is a raytracer able to render a wide
  155.           variety of shapes and surfaces.  The means of description range
  156.           from standard primitives like box, sphere, etc. to 3 variable
  157.           polynomial expression, and finally (and slowest of all) surfaces
  158.           containing transcendental functions like sin, cos, log.  The
  159.           files associated with Polyray are distributed in three pieces:
  160.           the executable, a collection of document files, and a collection
  161.           of data files.
  162.  
  163.           As of version 1.5, Polyray is a Shareware program, rather than
  164.           Freeware.  If you enjoy this program, use it frequently, and can
  165.           afford to pay a registration fee, then send $35 to:
  166.  
  167.                Alexander Enzmann
  168.                20 Clinton St.
  169.                Woburn, Ma 01801
  170.                USA
  171.  
  172.           Please include your name and mailing address.
  173.  
  174.           If you formally register this program, you will receive free the
  175.           next release of Polyray, when it occurs.  In addition you will be
  176.           contributing to my ability to purchase software tools to make
  177.           Polyray a better program.  If you don't register this program,
  178.           don't feel bad - I'm poor too - but you also shouldn't expect as
  179.           prompt a response to questions or bugs.  Note that the Polyray
  180.           executables and the Polyray documents (including this document)
  181.           are copyrighted.  The data files are public domain, you may use
  182.           them in any way you please.
  183.  
  184.           If you want a good reference book about raytracing, buy the book:
  185.           "Introduction to Ray Tracing", edited by Andrew Glassner,
  186.           Academic Press, 1989.  That book is excellent and will provide
  187.           many of the background details that are not contained here.  For
  188.           an abbreviated list of Polyray's syntax, see the file
  189.           "quickref.txt".
  190.  
  191.           This document contains a step by step description of a simple
  192.           scene file to get you familiar with the structure of Polyray
  193.           data.  By working through the example and by reviewing the
  194.           examples in the data archive, you will be able to see how the
  195.           various features are used.
  196.  
  197.           The data files are ASCII text, the image file formats are Targa
  198.           (see section 3.1 for the supported input and output formats).  It
  199.           is unlikely that other image formats will be supported.  The
  200.           Targa format is supported by many image processing programs so if
  201.           you need to translate between Targa and something else it is
  202.  
  203.                                                                               2
  204.  
  205.  
  206.           quite simple.  (Using the Targa formats also means that I didn't
  207.           have to define my own format and then build conversion programs
  208.           or try to convince others to build conversion programs.)
  209.  
  210.           The only display mode is the standard 320x200 VGA color mode.  I
  211.           tried to get good SVGA display code working, but with all the
  212.           alternatives it was just a bit too much.  For this reason, the
  213.           display for Polyray should be considered an aid during debugging
  214.           of images, and as a way to monitor the status of the image you
  215.           are rendering.  For viewing the final image, there are many image
  216.           viewers and many image format conversion programs that will
  217.           convert TGA to whatever format you prefer (PICLAB being one of
  218.           the best for all purpose work).
  219.  
  220.           The standard executable requires IBM PC compatible with at least
  221.           a 386 and 387, VGA graphics, and a minimum of 2 Mbytes of RAM to
  222.           run.  Other memory models will be made available if enough
  223.           requests are made.  The distributed executable uses a DOS
  224.           extender in order to grab as much memory as is available.  It has
  225.           been successfully run with both HIMEM.SYS, and 386MAX.SYS.  Under
  226.           Windows it will run in a DOS window, however if you use the
  227.           graphics display it will need to be run full screen.
  228.  
  229.           I'm interested in any comments/bug reports.  I can be reached via
  230.           email by:
  231.  
  232.                Compuserve as: Alexander Enzmann 70323,2461
  233.  
  234.                Internet as:   xander@mitre.org
  235.  
  236.           or via the postal service at:
  237.  
  238.                Alexander Enzmann
  239.                20 Clinton St.
  240.                Woburn, Ma 01801
  241.                USA
  242.  
  243.           1.1 Origin and Credits
  244.  
  245.           This original code for this program was based on the "mtv" ray-
  246.           tracer, written (and placed in the public domain) by Mark
  247.           VandeWettering.
  248.  
  249.           Many thanks go to David Mason for his numerous comments and
  250.           suggestions (and for adding a new feature to DTA every time I
  251.           needed to test something).  Thanks also to the Cafe Algiers in
  252.           Cambridge Ma. for providing a place to get heavily caffinated and
  253.           rap about ray-tracing and image processing for hours at a time.
  254.  
  255.                                                                               3
  256.  
  257.  
  258.  
  259.           1.2 Useful tools
  260.  
  261.           There are several types of tools that you will want to have to
  262.           work with
  263.           this program (in relative order of importance):
  264.  
  265.                o  An ASCII text editor for preparing and modifying input
  266.                   files.
  267.  
  268.                o  A picture viewer for viewing images.
  269.  
  270.                o  An image processing program for translation between Targa
  271.                   and some other format.
  272.  
  273.                o  An animation generator that will take a series of Targa
  274.                   images and produce an animation file.
  275.  
  276.                o  An animation viewer for playing an animation on the
  277.                   screen.
  278.  
  279.  
  280.           For the IBM-PC/Clone world (which is what I use at home), there
  281.           are several popular and easily available programs:  "PICLAB",
  282.           which will read process and write several popular graphics file
  283.           formats,  "VPIC" (Shareware) which displays images quickly and
  284.           supports many different video boards, "DTA" which will take a
  285.           bunch of Targa files and produce a "FLI" format animation, and
  286.           "aaplay" or "play80" which will show a FLI on a VGA screen.
  287.  
  288.           1.3 Contents of this document
  289.  
  290.           This document describes the input format and capabilities of the
  291.           "Polyray" ray-tracing program.  The following features are
  292.           supported:
  293.  
  294.                o Viewpoint (camera) characteristics,
  295.  
  296.                o Positional (point), directional (spotlight) light sources,
  297.                  and functional (textured) lights.
  298.  
  299.                o Background color,
  300.  
  301.                o Surface characteristics of objects,
  302.  
  303.                                                                               4
  304.  
  305.  
  306.  
  307.                o Shape primitives:
  308.  
  309.                   Bezier patch, blob, box, cone, cylinder, disc, implicit
  310.                   function, height field, lathe surface, parabola,
  311.                   polygon, polynomial function, sphere, sweep surface,
  312.                   torus, triangular patches
  313.  
  314.                o Animation support,
  315.  
  316.                o Conditional processing,
  317.  
  318.                o Include files,
  319.  
  320.                o Named values and objects.
  321.  
  322.                o Constructive Solid Geometry (CSG)
  323.  
  324.                o Grids of objects
  325.  
  326.                o User definable (functional) textures
  327.  
  328.                o Initialization file for default values
  329.  
  330.  
  331.           1.4 Quick demo
  332.  
  333.           This section describes one of the simplest possible data files: a
  334.           single sphere and a single light source.  In what follows
  335.           anything following a double slash, "//" is a comment and is
  336.           ignored by Polyray.  The data file is the following indented
  337.           lines.  You can either use the file "sphere.pi" in the data
  338.           archive, or copy these declarations into a new file.
  339.  
  340.                // We start by setting up the camera.  This is where the eye
  341.                // is located, and describes how wide a field of view will
  342.                // be used, and the resolution (# of pixels wide and high)
  343.                // of the resulting image.
  344.                viewpoint {
  345.                   from <0,0,-8>        // The location of the eye
  346.                   at <0,0,0>           // The point that we are looking at
  347.                   up <0,1,0>           // The direction that will be up
  348.                   angle 45             // The vertical field of view
  349.                   resolution 160, 160  // The image will be 160x160 pixels
  350.                   }
  351.  
  352.                // Next define the color of the background.  This is the
  353.                // color that is used for any pixel that isn't part of an
  354.                // object.  In this file it will color the image around the
  355.                // sphere.
  356.  
  357.                                                                               5
  358.  
  359.  
  360.                background skyblue
  361.  
  362.                // Next is a light source.  This is a point light source a
  363.                // little above, to the left, and behind the eye.
  364.                light <-10,3, -20>
  365.  
  366.                // The following declaration is a "texture" that will be
  367.                // applied to the sphere.  It will be red at every point but
  368.                // where the light is reflecting directly towards the eye -
  369.                // at that point there will be a bright white spot.
  370.                define shiny_red
  371.                texture {
  372.                   surface {
  373.                      ambient red, 0.2      // Always a little red
  374.                      diffuse red, 0.4      // Where the light is hitting
  375.                                            // the sphere, the color will be
  376.                                            // a little brighter.
  377.                      specular white, 0.8   // A white highlight.
  378.                      microfacet Reitz 10   // The highlight drops to half
  379.                                            // its intensity at an angle of
  380.                                            // 10 degrees.
  381.                      }
  382.                   }
  383.  
  384.                // Finally we declare the sphere.  It sits right at the
  385.                // origin, and has a radius of two.  Following the
  386.                // declaration of the sphere, we associate the texture
  387.                // declared above.
  388.                object {
  389.                   sphere <0, 0, 0>, 2
  390.                   shiny_red
  391.                   }
  392.  
  393.           Now that we have a data file, lets render it and show it on the
  394.           screen.  First of all we can look at a wireframe representation
  395.           of the file.  Enter the following commands (DOS prompts are in
  396.           capitals).
  397.  
  398.              C> polyray sphere.pi -r 2 -V 1 -W
  399.  
  400.                An outline of the sphere will be drawn on the screen, press
  401.                any key to get back to DOS
  402.  
  403.           Next lets do a raytrace.  Enter the following:
  404.  
  405.              C> polyray sphere.pi -V 1
  406.  
  407.                The sphere will be drawn a line at a time, when it is done
  408.                you will be returned to DOS
  409.  
  410.  
  411.                                                                               6
  412.  
  413.  
  414.           The output image will be the default output file, "out.tga".  You
  415.           can view it directly with VPIC or TGVIEW (although VPIC will not
  416.           have the full range of colors that were generated by the
  417.           raytrace).  If you have PICLAB, then the following commands will
  418.           load the image, map its colors into a spectrum that matches the
  419.           colors in the image, then will display it.
  420.  
  421.                C> piclab
  422.                > tload out
  423.                > makepal
  424.                > map
  425.                > show
  426.  
  427.                hit any key to get back to PICLAB's command line
  428.  
  429.                > quit
  430.                C>
  431.  
  432.           You should see a greatly improved image quality over the display
  433.           that is shown during tracing.
  434.  
  435.           Now that you have seen a simple image, you have two options: go
  436.           render some or all of the files in the data archive, or continue
  437.           reading the documents.  For those of you that prefer immediately
  438.           getting started, there are a series of DOS batch files that
  439.           pretty well automate the rendering of the sample scenes.  (When
  440.           you unzip the data files, remember to use the /d switch so that
  441.           all the subdirectories will be created.)
  442.  
  443.           1.5 Command Line Options
  444.  
  445.           A number of operations can be manipulated through values in an
  446.           initialization file, within the data file, or from the command
  447.           line (processed in that order, with the last read having the
  448.           highest precedence).  The command line values will be displayed
  449.           if no arguments are given to Polyray.
  450.  
  451.           The values that can be specified at the command line, with a
  452.           brief description of their meaning are:
  453.  
  454.                -a             Perform simple antialiasing (neighbor
  455.                               averaging)
  456.  
  457.                -A             Perform adaptive antialiasing (based on
  458.                               threshold)
  459.  
  460.                -b pixels      Set the maximum number of pixels that will be
  461.                               calculated between file flushes
  462.  
  463.                -B             Flush the output file every scan line
  464.  
  465.                                                                               7
  466.  
  467.  
  468.  
  469.                -d probability Dither objects using the given probability
  470.  
  471.                -D scale       Dither all rays using the given probability
  472.  
  473.                -J             Perform jittered antialiasing (fixed # of
  474.                               samples/pixel)
  475.  
  476.                -o filename    The output file name, the default output
  477.                               file name if not specified is "out.tga"
  478.  
  479.                -p bits/pixel  Set the number of bits per pixel in the
  480.                               output file (must be one of 8, 16, 24, 32)
  481.  
  482.                -P pallette    Which pallette option to use [0=grey, 1=666,
  483.                               2=884]
  484.  
  485.                -q flags       Turn on/off various global shading options
  486.  
  487.                -Q             Abort if any key is hit during trace
  488.  
  489.                -r renderer    Which rendering method: [0=raytrace, 1=scan
  490.                               convert, 2=wireframe]
  491.  
  492.                -R             Resume an interrupted trace.
  493.  
  494.                -s samples     # of samples per pixel when performing
  495.                               antialiasing
  496.  
  497.                -t status_vals Status display type
  498.                               [0=none,1=totals,2=line,3=pixel].
  499.  
  500.                -T threshold   Threshold to start oversampling
  501.  
  502.                -u             Write the output file in uncompressed form
  503.  
  504.                -v             Trace from bottom to top
  505.  
  506.                -V mode        Use VGA display while tracing [0=none,1=VGA]
  507.  
  508.                -W             Wait for key before clearing display
  509.  
  510.                -x columns     Set the x resolution
  511.  
  512.                -y lines       Set the y resolution
  513.  
  514.                -z start_line  Start a trace at a specified line
  515.  
  516.  
  517.           If no arguments are given then Polyray will give a brief
  518.  
  519.                                                                               8
  520.  
  521.  
  522.           description of the command line options.
  523.  
  524.           1.6 Initialization File
  525.  
  526.           The first operation carried out by Polyray is to read the
  527.           initialization file "polyray.ini".  This file can be used to tune
  528.           a number of the default variables used during rendering.  This
  529.           file must appear in the current directory.  This file does not
  530.           have to exist, it is typically used as a convenience to eliminate
  531.           retyping command line parameters.
  532.  
  533.           Each entry in the initialization file must appear on a separate
  534.           line, and have the form:
  535.  
  536.                default_name   value
  537.  
  538.           The names are text.  The values are numeric for some names, and
  539.           text for others.  The allowed names and values are:
  540.  
  541.             abort_test       true/false/on/off
  542.             alias_threshold  [Min value to start adaptive antialiasing]
  543.             antialias        none/filter/jitter/adaptive
  544.             display          none/vga
  545.             max_level        [max depth of recursion]
  546.             max_lights       [max # of lights]
  547.             max_queue_size   [max # of objects in a priority queue]
  548.             max_samples      [# samples for antialiasing]
  549.             pixel_size       [8, 16, 24, 32]
  550.             pixel_encoding   none/rle
  551.             renderer         ray_trace/scan_convert/wire_frame
  552.             shade_flags      [default/bit mask of flags, see sec 1.7.1.4]
  553.             shadow_tolerance [minimum distance for blocking objects]
  554.             status           none/totals/line/pixel
  555.         warnings         on/off
  556.  
  557.           A typical example of "polyray.ini" would be:
  558.  
  559.             abort_test       off
  560.             alias_threshold  0.05
  561.             antialias        adaptive
  562.             display          vga
  563.             max_samples      8
  564.             pixel_size       24
  565.             status           line
  566.  
  567.           If no initialization file exists, then Polyray will use the
  568.           following default values:
  569.  
  570.             abort_test       on
  571.             alias_threshold  0.2
  572.  
  573.                                                                               9
  574.  
  575.  
  576.             antialias        none
  577.             display          none
  578.             max_level        5
  579.             max_lights       64
  580.             max_queue_size   128
  581.             max_samples      4
  582.             pixel_size       16
  583.             pixel_encoding   rle
  584.             renderer         ray_trace
  585.             shade_flags      default
  586.             shadow_tolerance 0.001
  587.             status           line
  588.         warnings         on
  589.  
  590.  
  591.           1.7 Rendering Options
  592.  
  593.           Polyray supports three very distinct means of rendering scenes:
  594.           raytracing, polygon scan conversion, and wireframe.  Raytracing
  595.           is often a very time consuming process, however a number of types
  596.           of surfaces can be rendered with this technique that are very
  597.           difficult or impossible using traditional techniques.
  598.  
  599.           1.7.1 Raytracing
  600.  
  601.           Polyray is at heart a raytracer.  The quality of the images that
  602.           can be produced is entirely a function of how long you want to
  603.           wait for results.  There are certain options that allow you to
  604.           adjust how you want to trade off quality Vs speed Vs memory
  605.           requirements.
  606.  
  607.           The basic operation in raytracing is that of shooting a ray from
  608.           the eye, through a pixel, and finally hitting an object.  For
  609.           each type of primitive there is specialized code that helps
  610.           determine if a ray has hit that primitive.  The standard way that
  611.           Polyray generates an image is to use one ray per pixel and to
  612.           test that ray against all of the objects in the data file.
  613.  
  614.           The following sections describe how you can cause Polyray to use
  615.           more rays per pixel to improve image quality, skip pixels or
  616.           objects in a probabilistic way to improve rendering speed, or
  617.           partition objects in such a way that not all objects need to be
  618.           tested for every ray.  Each of these techniques has benefits and
  619.           drawbacks.
  620.  
  621.           1.7.1.1 Antialiasing
  622.  
  623.           The representation of rays is as a 1 dimensional line.  On the
  624.           other hand pixels and objects have a definite size.  This can
  625.           lead to a problem known as "aliasing", where a ray may not
  626.  
  627.                                                                              10
  628.  
  629.  
  630.           intersect an object because the object only partially overlaps a
  631.           pixel, or the pixel should have color contributed by several
  632.           objects that overlap it, none of which completely fills the
  633.           pixel. Aliasing often shows up as a staircase effect on the edges
  634.           of objects.
  635.  
  636.           Polyray offers three ways to reduce aliasing: by filtering, by
  637.           oversampling with a fixed number of samples, and by adaptive
  638.           oversampling.  Filtering smoothes the output image by averaging
  639.           the color values of neighboring pixels to the pixel being
  640.           rendered.  Oversampling is performed by adding extra rays through
  641.           random jittering of the direction of the ray within the pixel
  642.           being traced.  By averaging the result of all of the rays that
  643.           are shot through a single pixel, aliasing problems can be greatly
  644.           reduced.
  645.  
  646.           The filtering process adds little overhead to the rendering
  647.           process, however the resolution of the image is degraded by the
  648.           averaging process.  Jittered antialiasing slows down the
  649.           rendering process in direct proportion to the number of extra
  650.           rays, but results in the best image quality.
  651.  
  652.           Oversampling can be performed in two ways, either by using a
  653.           fixed number of rays per pixel, or by adaptive antialiasing.  The
  654.           former will always shoot the same number of rays through each
  655.           pixel, regardless of picture complexity.  The latter initially
  656.           shoots just one ray through each pixel, if a pixel's color is
  657.           significantly different that any of its neighbors, then
  658.           additional rays are fired.
  659.  
  660.           The two initialization (and command line) variables that will
  661.           affect the performance of adaptive antialiasing are
  662.           "alias_threshold" and "max_samples".  The first is a measure of
  663.           how different a pixel must be with respect to its neighbors
  664.           before antialiasing will kick in.  If a pixel has the value: <r1,
  665.           g1, b1>, and it's neighbor has the value <r2, g2, b2> (RGB values
  666.           between 0 and 1 inclusive), then the "distance" between the two
  667.           colors is:
  668.  
  669.                dist = sqrt((r1 - r2)^2 + (b1 - b2)^2 + (g1 - g2)^2)
  670.  
  671.           This is the standard Pythagorean formula for values specified in
  672.           RGB.  If "dist" is greater than the value of "alias_threshold",
  673.           then extra rays will be fired through the pixel in order to
  674.           determine an averaged color for that pixel.
  675.  
  676.                                                                              11
  677.  
  678.  
  679.  
  680.           Note:  Performing the distance test in RGB space may not be the
  681.           best way to determine when antialiasing should occur.  Future
  682.           versions of Polyray may perform distance calculations in LAB
  683.           space.
  684.  
  685.           1.7.1.2 Dithering
  686.  
  687.           In order to speed up the generation of an image (and to produce
  688.           some interesting effects), several dithering options are
  689.           available: Dithering all rays, dithering all objects, and
  690.           dithering of specific objects.  Associated with each option is a
  691.           probability value between 0 and 1.  During rendering, if the
  692.           dithering option is being used, Polyray generates a random number
  693.           between 0 and 1 and compares it to the probability value.  If the
  694.           random number is greater than the probability value then the ray
  695.           (or object) will be ignored.
  696.  
  697.           Dithering of rays is a way to sample the entire image, for
  698.           example if a probability value of 0.5 is given, then only half of
  699.           all rays will be traced through the scene.  The final image will
  700.           be severely degraded, however the amount of time taken to trace
  701.           the scene will be cut approximately in half.
  702.  
  703.           Dithering of objects is a way to simulate transparency, without
  704.           the overhead of generating secondary rays during the raytracing
  705.           process.  It also can be used as an interesting optical effect -
  706.           during an animation, if the probability value is successively
  707.           lowered from 1 to 0, the object will dissolve away.
  708.  
  709.           Negative dither values as well as those above 1.0 will have no
  710.           effect.  The way dithering works is:  Right before a check is
  711.           made to see if the current ray will intersect an object a random
  712.           number between 0 and 1 is generated.  If this number is less than
  713.           the dither value then the intersection check will be made.  If
  714.           the random number is greater than the dither value then Polyray
  715.           assumes that there is no hit.
  716.  
  717.           Sample files:  dither.pi, bnddithr.pi
  718.  
  719.           1.7.1.3 Bounding Slabs
  720.  
  721.           For scenes with large numbers of small objects, there are
  722.           optimization tricks that can take advantage of the distribution
  723.           of the objects.  An easy one to implement, and one that often
  724.           results in huge time savings are bounding slabs. The basic idea
  725.           of a bounding slab is to sort all objects along a particular
  726.           direction.  Once this sorting step has been performed, then
  727.           during rendering the ray can be quickly checked against a slab
  728.           (which can represent many objects rather than just one) to see if
  729.  
  730.                                                                              12
  731.  
  732.  
  733.           intersection tests need to be made on the contents of the slab.
  734.  
  735.           The most important caveats with Polyray's implementation of
  736.           bounding slabs are:
  737.  
  738.                o  Scenes with only a few large objects will derive little
  739.                   speed benefits.
  740.  
  741.                o  If there is a lot of overlap of the positions of the
  742.                   objects in the scene, then there will be little
  743.                   advantage to the slabs.
  744.  
  745.                o  If the direction of the slabs does not correspond to a
  746.                   direction that easily sorts objects, then there will be
  747.                   little speed gained.
  748.  
  749.  
  750.           However, for data files that are generated by another program,
  751.           the requirements for effective use of bounding slabs are often
  752.           met.  For example, most of the data files generated by the SPD
  753.           programs will be rendered orders of magnitude faster with
  754.           bounding slabs than without.
  755.  
  756.           1.7.1.4 Shading Quality Flags
  757.  
  758.           By specifying a series of bits, various shading options can be
  759.           turned on and off.  The value of each flag, as well as the
  760.           meaning are:
  761.  
  762.                1    Shadow_Check   Shadows will be generated
  763.  
  764.                2    Reflect_Check  Reflectivity will be tested
  765.  
  766.                4    Transmit_Check Check for refraction
  767.  
  768.                8    Two_Sides      If on, highlighting will be performed on
  769.                                    both sides of a surface.
  770.  
  771.                16   Cast_Shadow    Determines if an object casts shadows.
  772.  
  773.                32   Primary_Rays   If off, then primary rays (those from
  774.                                    the eye) are not checked against the
  775.                                    object.
  776.  
  777.           The default settings of these flags are:
  778.  
  779.                raytracing          Shadow_Check + Reflect_Check +
  780.                                    Transmit_Check + Two_Sides + Cast_Shadow
  781.                                    + Primary_Rays (= 63)
  782.  
  783.  
  784.                                                                              13
  785.  
  786.  
  787.                scan conversion     [Two_Sides, = 8]
  788.  
  789.                wireframe           Not applicable
  790.  
  791.  
  792.           The assumption made is that during raytracing the highest quality
  793.           is desired, and consequently every shading test is made.  The
  794.           assumption for scan conversion is that you are trying to render
  795.           quickly, and hence most of the complex shading options are turned
  796.           off.
  797.  
  798.           If any of the flags are explicitly set and scan conversion is
  799.           used to render the scene, then at every pixel that is displayed,
  800.           a recursive call to the raytracer will be made to determine the
  801.           correct shading.  Note that due to the faceted nature of objects
  802.           during scan conversion, shadowing, and especially refraction can
  803.           get messed up during scan conversion.
  804.  
  805.           For example if you want to do a scan conversion that contains
  806.           shadows, you would use the following:
  807.  
  808.                polyray xxx.pi -r 1 -q 1
  809.  
  810.           or if you wanted to do raytracing with no shadows, reflection
  811.           turned on, transparency turned off, and with diffuse and specular
  812.           shading performed for both sides of surfaces you would use
  813.           options 2 and 8:
  814.  
  815.                polyray xxx.pi -q 10
  816.  
  817.           Note: texturing cannot be turned off.
  818.  
  819.           1.7.2 Scan Conversion
  820.  
  821.           In order to support a quicker render of images Polyray can render
  822.           most primitives as a series of polygons.  Each polygon is scan
  823.           converted using a Z-Buffer for depth information, and a S-Buffer
  824.           for color information.
  825.  
  826.           The scan conversion process does not by default provide support
  827.           for: shadows, reflectivity, or transparency.  It is possible to
  828.           instruct Polyray to use raytracing to perform these shading
  829.           operations through the use of either the global shade flags or by
  830.           setting shade flags for a specific object.  An alternative method
  831.           for quickly testing shadows using shadow buffers is in the works.
  832.  
  833.           The memory requirements for performing scan conversion can be
  834.           quite substantial.  You need at least as much memory as is
  835.           required for raytracing, plus at least 7 bytes per pixel for the
  836.           final image.  In order to correctly keep track of depth and color
  837.  
  838.                                                                              14
  839.  
  840.  
  841.           - 4 bytes are used for the depth of each pixel in the Z-Buffer
  842.           (32 bit floating point number), and 3 bytes are used for each
  843.           pixel in the S-Buffer (1 byte each for red, green, and blue).
  844.  
  845.           During scan conversion, the number of polygons used to cover the
  846.           surface of a primitive is controlled using the keywords
  847.           "u_steps", and "v_steps".  These two values control how many
  848.           steps around and along the surface of the object values are
  849.           generated to create polygons.  The higher the number of steps,
  850.           the smoother the final appearance.  Note however that if the
  851.           object is very small then there is little reason to use a fine
  852.           mesh - hand tuning is sometimes required to get the best balance
  853.           between speed and appearance.
  854.  
  855.           Generating isosurfaces for blobs, polynomial functions and
  856.           implicit functions, followed by polygonalization of the surfaces
  857.           is performed using a "marching cubes" algorithm.  Currently the
  858.           value of "u_steps" determines the number of slices along the x-
  859.           axis, and the value of "v_steps" controls the number of slices
  860.           along the y-axis and along the z-axis.  Future versions may
  861.           introduce a third value to allow independent control of y and z.
  862.  
  863.           1.7.3 Wireframe
  864.  
  865.           In most cases the fastest way to display a model is by showing a
  866.           wireframe representation.  Polyray supports this as a variant of
  867.           the scan conversion process.  When drawing a wireframe image only
  868.           the edges of the polygons that are generated as part of scan
  869.           conversion are drawn onto the screen.  A big problem with
  870.           wireframe representations is that CSG operations are not
  871.           performed.  If you use CSG intersection, difference, or clipping,
  872.           you may see a lot of stuff that will not appear in the final
  873.           image.
  874.  
  875.           Note that there are images that render slower in scan conversion
  876.           and wireframe than raytracing!  These are typically those files
  877.           that contain large numbers of spheres and cones.  The scan
  878.           conversion process generates every possible part of each object,
  879.           whereas the raytracer is able to sort the objects an only display
  880.           the visible parts of the surfaces.
  881.  
  882.           2  Detailed description of the Polyray input format:
  883.  
  884.           An input file describes the basic components of an image:
  885.  
  886.                o A viewpoint that characterizes where the eye is, where it
  887.                  is looking and what its orientation is.
  888.  
  889.                o Objects, their shape, placement, and orientation.
  890.  
  891.  
  892.                                                                              15
  893.  
  894.  
  895.                o Light sources, their placement and color.
  896.  
  897.                o Textures for coloring and patterning surfaces.
  898.  
  899.  
  900.           Beyond the fundamentals, there are many components that exist
  901.           either as a convenience such as definable expressions, or
  902.           textures.  This section of the document describes in detail the
  903.           syntax of all of the components of an input file
  904.  
  905.           2.1 Expressions
  906.  
  907.           There are four basic types of expressions that are used in
  908.           polyray:
  909.  
  910.                o  fexper: Floating point expression (i.e. 0.5, 2 *
  911.                   sin(1.33)).  These are used at any point a floating
  912.                   point value is needed, such as the radius of a sphere or
  913.                   the amount of contribution of a part of the lighting
  914.                   model.
  915.  
  916.                o  vexper:- Vector valued expression  (i.e. <0, 1, 0>, red,
  917.                   12 * <2, sin(x), 17> + P).  Used for color expressions,
  918.                   describing positions, describing orientations, etc.
  919.  
  920.                o  arrays: Lists of expressions (i.e. [0, 1, 17, 42],
  921.                   [<0,1,0>, <2*sin(theta), 42, -4>, 2*<3, 7, 2>]
  922.  
  923.                o  cexper: Conditional expression (i.e. x < 42).
  924.  
  925.  
  926.           The following sections describe the syntax for each of these
  927.           types of expressions, as well as how to define variables in terms
  928.           of expressions.
  929.  
  930.           2.1.1 Numeric expressions
  931.  
  932.           In most places where a number can be used (i.e. scale values,
  933.           angles, RGB components, etc.) a simple floating point expression
  934.           (fexper) may be used.  These expressions can contain any of the
  935.           following terms:
  936.  
  937.             val                     A floating point number or defined
  938.                                     value
  939.             '(' fexper ')'          Parenthesised expression
  940.             fexper ^ fexper         Same as pow(x, y)
  941.             fexper * fexper         Multiplication
  942.             fexper / fexper         Division
  943.             fexper + fexper         Addition
  944.             fexper - fexper         Subtraction
  945.  
  946.                                                                              16
  947.  
  948.  
  949.             -fexper                 Unary minus
  950.             acos(fexper)            Arccosine, (radians for all trig
  951.                                     functions)
  952.             asin(fexper)            Arcsin
  953.             atan(fexper)            Arctangent
  954.             ceil(fexper)            Ceiling function
  955.             cos(fexper)             Cosine
  956.             cosh(fexper)            Hyperbolic cosine
  957.             degrees(fexper)         Converts radians to degrees
  958.             exp(fexper)             e^x, standard exponential function
  959.             fabs(fexper)            Absolute value
  960.             floor(fexper)           Floor function
  961.             fmod(fexper, fexper)    Modulus function for floating point
  962.                                     values
  963.             ln(fexper)              Natural logarithm
  964.             log(fexper)             Logarithm base 10
  965.             noise(vexper, fexper)   Correlated noise function
  966.             pow(fexper, fexper)     Exponentiation (x^y)
  967.             radians(fexper)         Converts degrees to radians
  968.             sawtooth(fexper)        Sawtooth function (range 0 -> 1)
  969.             sin(fexper)             Sine
  970.             sinh(fexper)            Hyperbolic sine
  971.             sqrt(fexper)            Square root
  972.             tan(fexper)             Tangent
  973.             tanh(fexper)            Hyperbolic tangent
  974.             visible(vexper, vexper) Returns 1 if second point visible from
  975.                                     first.
  976.             vexper[i]               Extract component i from a vector or
  977.                                     an array.
  978.             vexper . vexper         Dot product of two vectors
  979.             |fexper|                Absolute value (same as fabs)
  980.             |vexper|                Length of a vector
  981.  
  982.           2.1.2 Vector Expressions
  983.  
  984.           In most places where a vector can be used (i.e. color values,
  985.           rotation angles, locations, ...), a vector expression is allowed.
  986.           The expressions can contain any of the following terms:
  987.  
  988.  
  989.             vexper + vexper         Addition
  990.             vexper - vexper         Subtraction
  991.             vexper * vexper         Cross product
  992.             vexper * fexper         Scaling of a vector by a scalar
  993.             fexper * vexper         Scaling of a vector by a scalar
  994.             vexper / fexper         Inverse scaling of a vector by a
  995.                                     scalar
  996.  
  997.             brownian(vexper)        Makes a random displacement of a
  998.                                     vector
  999.  
  1000.                                                                              17
  1001.  
  1002.  
  1003.  
  1004.             color_wheel(x, y, z)    RGB color wheel using x and z (y
  1005.                                     ignored), the color returned is based
  1006.                                     on <x, z> using the chart below:
  1007.  
  1008.                                               Z-Axis
  1009.                                                  ^
  1010.                                                  |
  1011.                                                  |
  1012.                                            Green   Yellow
  1013.                                                \   /
  1014.                                                 \ /
  1015.                                        Cyan ---- * ---- Red  -----> X-Axis
  1016.                                                 / \
  1017.                                                /   \
  1018.                                             Blue   Magenta
  1019.  
  1020.                                     Intermediate colors are generated by
  1021.                                     interpolation.
  1022.  
  1023.             rotate(vexper, vexper)  Rotate the point given in the first
  1024.                                     argument by the angles given in the
  1025.                                     second argument. (angles in degrees)
  1026.  
  1027.             rotate(vexper, vexper,
  1028.                    fexper)          Rotate the point in the first argument
  1029.                                     around the axis given in the second
  1030.                                     argument, by the angle in the third
  1031.                                     argument. (angle in degrees)
  1032.  
  1033.             reflect(vexper, vexper) Reflect the first vector about the
  1034.                                     second vector (particularly useful in
  1035.                                     environment maps)
  1036.  
  1037.           2.1.3 Arrays
  1038.  
  1039.           Arrays are a way to represent data in a convenient list form.  A
  1040.           good use for arrays is to hold a number of locations for polygon
  1041.           vertices or as locations for objects in successive frames of an
  1042.           animation.
  1043.  
  1044.           As an example, a way to define a tetrahedron (4 sided solid) is
  1045.           to define its vertices, and which vertices make up its faces.  By
  1046.           using this information in an object declaration, we can make a
  1047.           tetrahedron out of polygons very easily.
  1048.  
  1049.                                                                              18
  1050.  
  1051.  
  1052.  
  1053.              define tetrahedron_faces
  1054.                [<0, 1, 2>, <0, 2, 3>, <0, 3, 1>, <1, 3, 2>]
  1055.  
  1056.              define tetrahedron_vertices
  1057.                [<0, 0, sqrt(3)>, <0, (2*sqrt(2)*sqrt(3))/3, -sqrt(3)/3>,
  1058.                 <-sqrt(2), -(sqrt(2)*sqrt(3))/3, -sqrt(3)/3>,
  1059.                 <sqrt(2), -(sqrt(2)*sqrt(3))/3, -sqrt(3)/3>]
  1060.  
  1061.              define tcf tetrahedron_faces
  1062.              define tcv tetrahedron_vertices
  1063.              define tetrahedron
  1064.              object {
  1065.                 object { polygon 3, tcv[tcf[ 0][0]],
  1066.                          tcv[tcf[ 0][1]], tcv[tcf[ 0][2]] } +
  1067.                 object { polygon 3, tcv[tcf[ 1][0]],
  1068.                          tcv[tcf[ 1][1]], tcv[tcf[ 1][2]] } +
  1069.                 object { polygon 3, tcv[tcf[ 2][0]],
  1070.                          tcv[tcf[ 2][1]], tcv[tcf[ 2][2]] } +
  1071.                 object { polygon 3, tcv[tcf[ 3][0]],
  1072.                          tcv[tcf[ 3][1]], tcv[tcf[ 3][2]] }
  1073.                 }
  1074.  
  1075.  
  1076.           What happened in the object declaration is that each polygon
  1077.           grabbed a series of vertex indices from the array
  1078.           "tetrahedron_faces", then used that index to grab the actual
  1079.           location in space of that vertex.
  1080.  
  1081.           Another example is to use an array to store a series of view
  1082.           directions so that we can use animation to generate a series of
  1083.           very distinct renders of the same scene:
  1084.  
  1085.              define location <0, 0, 0>
  1086.              define at_vecs [<1, 0, 0>, <-1, 0, 0>, < 0, 1, 0>, < 0,-1, 0>,
  1087.                              < 0, 0,-1>, < 0, 0, 1>]
  1088.              define up_vecs [< 0, 1, 0>, < 0, 1, 0>, < 0, 0, 1>,
  1089.                              < 0, 0,-1>, < 0, 1, 0>, < 0, 1, 0>]
  1090.  
  1091.              // Generate six frames
  1092.              start_frame 0
  1093.              end_frame 5
  1094.  
  1095.              // Each frame generates the view in a specific direction.  The
  1096.              // vectors stored in the arrays "at_vecs", and "up_vecs" turn
  1097.              // the camera in such a way as to generate image maps correct
  1098.              // for using in an environment map.
  1099.              viewpoint {
  1100.                 from location
  1101.                 at location + at_vecs[frame]
  1102.  
  1103.                                                                              19
  1104.  
  1105.  
  1106.                 up up_vecs[frame]
  1107.                 ...
  1108.                 }
  1109.  
  1110.              ... Rest of the data file ...
  1111.  
  1112.  
  1113.           Sample files: plyhdrn.pi, environ.pi
  1114.  
  1115.  
  1116.           2.1.4 Conditional Expressions
  1117.  
  1118.           Conditional expressions are used in one of two places:
  1119.           conditional processing of declarations (see section 2.7) or
  1120.           conditional value functions.
  1121.  
  1122.           cexper has one of the following forms:
  1123.  
  1124.                !cexper
  1125.                cexper && cexper
  1126.                cexper || cexper
  1127.                fexper < fexper
  1128.                fexper <= fexper
  1129.                fexper > fexper
  1130.                fexper >= fexper
  1131.                fexper == fexper
  1132.                vexper == vexper
  1133.  
  1134.           A use of conditional expressions is to define a texture based on
  1135.           other expressions, the format of this expression is:
  1136.  
  1137.                (cexper ? true_value : false_value)
  1138.  
  1139.           Where true_value/false_value can be either floating point or
  1140.           vector values.  This type of expression is taken directly from
  1141.           the equivalent in the C language.  An example of how this is used
  1142.           (from the file "spot1.pi") is:
  1143.  
  1144.              special surface {
  1145.                 color white
  1146.                 ambient (visible(W, throw_offset) == 0
  1147.                          ? 0
  1148.                          : (P[0] < 1 ? 1
  1149.                            : (P[0] > throw_length ? 0
  1150.                               : (throw_length - P[0]) / throw_length)))
  1151.                 transmission (visible(W, throw_offset) == 1
  1152.                               ? (P[0] < 1 ? 0
  1153.                                  : (P[0] > throw_length ? 1
  1154.                                     : P[0] / throw_length))
  1155.                               : 1), 1
  1156.  
  1157.                                                                              20
  1158.  
  1159.  
  1160.                 }
  1161.  
  1162.           In this case conditional statements are used to determine the
  1163.           surface characteristics of a cone defining the boundary of a
  1164.           spotlight.  The amount of ambient light is modified with distance
  1165.           from the apex of the cone, the visibility of the cone is modified
  1166.           based on both distance and on a determination if the cone is
  1167.           behind an object with respect to the source of the light.
  1168.  
  1169.           2.1.5 Run-Time expressions
  1170.  
  1171.           There are a few expressions that only have meaning during the
  1172.           rendering process:
  1173.  
  1174.                I              The direction of the ray that struck the
  1175.                               object
  1176.  
  1177.                P              The point of intersection in "object"
  1178.                               coordinates (you can also use x, y, or z to
  1179.                               represent a single component of P).
  1180.  
  1181.                N              The normal to the point of intersection in
  1182.                               "world" coordinates
  1183.  
  1184.                W              The point of intersection in "world"
  1185.                               coordinates
  1186.  
  1187.  
  1188.           These expressions describe the interaction of a ray and an
  1189.           object.  To use them effectively, you need to understand the
  1190.           distinction between "world" coordinates and "object" coordinates.
  1191.           Object coordinates describe a point or a direction with respect
  1192.           to an object as it was originally defined.  World coordinates
  1193.           describe a point with respect to an object after it has been
  1194.           rotated/translated/scaled.  Typically texturing is done in object
  1195.           coordinates so that as the object is moved around the texture
  1196.           will move with it.  On the other hand shading is done in world
  1197.           coordinates.
  1198.  
  1199.           NOTE: Capitalization of these variables is important.
  1200.  
  1201.           2.1.6 Named Expressions
  1202.  
  1203.           A major convenience for creating input files is the ability to
  1204.           create named definitions of surface models, object definitions,
  1205.           vectors, etc.  The way a value is defined takes one of the
  1206.           following forms:
  1207.  
  1208.                define token expression
  1209.                define token object { ... }
  1210.  
  1211.                                                                              21
  1212.  
  1213.  
  1214.                define token surface { ... }
  1215.                define token texture { ... }
  1216.                define token transform { ... }
  1217.  
  1218.           Objects, surfaces, and textures can either be instantiated as-is
  1219.           by using the token name alone, or it can be instantiated and
  1220.           modified:
  1221.  
  1222.              token,
  1223.           or
  1224.              token { ... modifiers ... },
  1225.  
  1226.           Polyray keeps track of what type of entity the token represents
  1227.           and will parse the expressions accordingly.
  1228.  
  1229.           Note: It is not possible to have two types of entities referred
  1230.           to by the same name.  If a name is reused, then a warning will be
  1231.           printed, and all references to that name will use the new
  1232.           definition from that point on.
  1233.  
  1234.           2.2 Definition of the viewpoint
  1235.  
  1236.           The viewpoint and its associated components define the position
  1237.           and orientation the view will be generated from.
  1238.  
  1239.           The format of the declaration is:
  1240.  
  1241.               viewpoint {
  1242.                  from vexper
  1243.                  at vexper
  1244.                  up vexper
  1245.                  angle fexper
  1246.                  hither fexper
  1247.                  resolution fexper, fexper
  1248.                  aspect fexper
  1249.                  yon fexper
  1250.                  dither_rays fexper
  1251.                  dither_objects fexper
  1252.                  max_trace_depth fexper
  1253.                  aperture fexper
  1254.                  focal_distance fexper
  1255.                  }
  1256.  
  1257.           Order of the entries defining the viewpoint is not important,
  1258.           unless you redefine some field. (In which case the last is used.)
  1259.  
  1260.           The parameters are:
  1261.  
  1262.             aspect            The ratio of width to height. (Default: 1.0.)
  1263.  
  1264.  
  1265.                                                                              22
  1266.  
  1267.  
  1268.             at                A position to be at the center of the image,
  1269.                               in XYZ world coordinates. (Default: <0, 0, 0>)
  1270.  
  1271.             angle             The field of view (in degrees), from the
  1272.                               center of the top row to the center of the
  1273.                               bottom row. (Default: 45 degrees)
  1274.  
  1275.             from              The eye location in XYZ. (Default: <0, 0, -10>)
  1276.  
  1277.             hither            Distance to front of view pyramid.  Any
  1278.                               intersection less than this value will be
  1279.                               ignored.  (Defaults: 1.0e-3)
  1280.  
  1281.             resolution        The number of pixels wide and high of the
  1282.                               raster. (Default: 256x256)
  1283.  
  1284.             up                A vector defining which direction is up, as
  1285.                               an XYZ vector. (Default: <0, 1, 0>)
  1286.  
  1287.             yon               Distance to back of view pyramid.  Any
  1288.                               intersection beyond this distance will be
  1289.                               ignored. (Defaults to 1.0e5)
  1290.  
  1291.             dither_rays       Rays will be skipped if a random number is
  1292.                               above the given value.
  1293.  
  1294.             dither_objects    For each ray, Ray-surface checks will skipped
  1295.                               for an object if a random number is above the
  1296.                               given value.
  1297.  
  1298.             max_trace_depth   This allows you to tailor the amount of
  1299.                               recursion allowed for scenes with reflection
  1300.                               and/or transparency. (Default: 5)
  1301.  
  1302.             aperture          If larger than 0, then extra rays are shot
  1303.                               (controlled by "max_samples" in the
  1304.                               initialization file) to produce a blurred
  1305.                               image.  (Good values are between 0.1 and
  1306.                               0.5.)
  1307.  
  1308.             focal_distance    Distance from the eye to the point that
  1309.                               things are in focus, this defaults to the
  1310.                               distance between "from" and "at".
  1311.  
  1312.           The view vectors will be coerced so that they are perpendicular
  1313.           to the vector from the eye (from) to the point of interest (at).
  1314.  
  1315.                                                                              23
  1316.  
  1317.  
  1318.  
  1319.           A typical declaration is:
  1320.  
  1321.              viewpoint {
  1322.                 from <0, 5, -5>
  1323.                 at   <0, 0,  0>
  1324.                 up   <0, 1,  0>
  1325.                 angle 30
  1326.                 resolution 320, 160
  1327.                 aspect 2
  1328.                 }
  1329.  
  1330.           In this declaration the eye is five units behind the origin, five
  1331.           units above the x-z plane and is looking at the origin.  The up
  1332.           direction is aligned with the y-axis, the field of view is 30
  1333.           degrees and the output file will default to 320x160 pixels.
  1334.  
  1335.           In this example it is assumed that pixels are square, and hence
  1336.           the aspect ratio is set to width/height.  If you were generating
  1337.           an image for a screen that has pixels half as wide as they are
  1338.           high then the aspect ratio would be set to one.
  1339.  
  1340.           2.3 Objects/Surfaces
  1341.  
  1342.           In order to make pictures, the light has to hit something.
  1343.           Polyray supports several primitive objects, and the following
  1344.           sections describe the syntax for describing the primitives, as
  1345.           well as how more complex primitives can be built from simple
  1346.           ones.
  1347.  
  1348.           The "object" declaration is how polyray associates a surface with
  1349.           its lighting characteristics, and its orientation.  This
  1350.           declaration includes one of the primitive shapes (sphere,
  1351.           polygon, ...), and optionally: a texture declaration (set to a
  1352.           matte white if none is defined), orientation declarations, or a
  1353.           bounding box declaration.
  1354.  
  1355.           The format the declaration is:
  1356.  
  1357.              object {
  1358.                 shape_declaration
  1359.                 [texture_declaration]
  1360.                 [transformation declarations]
  1361.                 [subdivision declarations]
  1362.                 [bounding box declaration]
  1363.                 }
  1364.  
  1365.           There are three separate ways that an object can be rendered by
  1366.           Polyray, raytracing, scan conversion, or wireframe.  The steps
  1367.           taken by each of these methods are:
  1368.  
  1369.                                                                              24
  1370.  
  1371.  
  1372.  
  1373.           Raytracing
  1374.  
  1375.                1) Find the object that seems closest to the eye along the
  1376.                   current ray.  The bounding slab process is what
  1377.                   determines what order objects will be tested against the
  1378.                   ray.
  1379.  
  1380.                2) Find all intersections of the ray with the object.  (Up
  1381.                   to the maximum number of intersections.)
  1382.  
  1383.           Scan Conversion
  1384.  
  1385.                1) The object is broken up into a number of rectangles (the
  1386.                   actual number depends on the values of "u_steps" and
  1387.                   "v_steps" in the object declarations).
  1388.  
  1389.                2) The rectangle is clipped so that only the visible part
  1390.                   will be rendered.
  1391.  
  1392.                3) The clipped polygon is scan converted a line at a time.
  1393.                   As the scan conversion takes place, the object and world
  1394.                   coordinates of the polygon are interpolated from
  1395.                   vertices.
  1396.  
  1397.                4) As each pixel is generated by scan conversion, its
  1398.                   distance from the eye is checked against a Z-Buffer.
  1399.  
  1400.                5) If the distance is less than the value in the Z-Buffer,
  1401.                   then any CSG and clipping operations associated with the
  1402.                   object are performed.
  1403.  
  1404.                6) If the pixel passes the depth check and CSG checks, then
  1405.                   the pixel is shaded using the texture information
  1406.                   associated with the object.  The depth to the pixel is
  1407.                   stored in the Z-Buffer and the color associated with the
  1408.                   pixel is stored in the S-Buffer.
  1409.  
  1410.  
  1411.           Wireframe
  1412.  
  1413.                1) The object is broken up into a number of rectangles (the
  1414.                   actual number depends on the values of "u_steps" and
  1415.                   "v_steps" in the object declarations).
  1416.  
  1417.                2) The rectangle is clipped so that only the visible part
  1418.                   will be rendered.
  1419.  
  1420.                3) The clipped rectangle is displayed on the screen.  CSG is
  1421.                   not taken into consideration in a wireframe image.
  1422.  
  1423.                                                                              25
  1424.  
  1425.  
  1426.  
  1427.  
  1428.           Determining if a point is inside an object is performed by
  1429.           evaluating the function that describes the object using the point
  1430.           of intersection.  If the value is less than or equal to 0 then
  1431.           the point is inside.  Some primitives do not have an inside
  1432.           (triangular patches), others do not have a well defined inside
  1433.           (cylinder).
  1434.  
  1435.           The following sub-sections describe the format of the individual
  1436.           parts of an object declaration.  (Note: The shape declaration
  1437.           MUST be first in the declaration, as any operations that follow
  1438.           have to have data to work on.)
  1439.  
  1440.           2.3.1 Object Modifiers
  1441.  
  1442.  
  1443.           2.3.1.1 Position and Orientation Modifiers
  1444.  
  1445.           The position, orientation, and size of an object can be modified
  1446.           through one of four linear transformations: translation,
  1447.           rotation, scaling, and shear.
  1448.  
  1449.           2.3.1.1.1 Translation
  1450.  
  1451.           Translation moves the position of an object by the number of
  1452.           units specified in the associated vector.  The format of the
  1453.           declaration is:
  1454.  
  1455.              translate <xt, yt, zt>
  1456.  
  1457.           For example the declaration:
  1458.  
  1459.              translate <0, 20, -4>
  1460.  
  1461.           will move the entire object up 20 units along the y axis and back
  1462.           4 units along the (negative) z axis.
  1463.  
  1464.           2.3.1.1.2 Rotation
  1465.  
  1466.           Rotation revolves the position of an object about the x, y, and z
  1467.           axes (in that order).  The amount of rotation is specified in
  1468.           degrees for each of the axes.  The direction of rotations follows
  1469.           a left-handed convention: if the thumb of your left hand points
  1470.           along the positive direction of an axis, then the direction your
  1471.           fingers curl is the positive direction of rotation.
  1472.  
  1473.           The format of the declaration is:
  1474.  
  1475.              rotate <xr, yr, zr>
  1476.  
  1477.                                                                              26
  1478.  
  1479.  
  1480.  
  1481.           For example the declaration:
  1482.  
  1483.              rotate <30, 0, 20>
  1484.  
  1485.           will rotate the object by 30 degrees about the x axis, followed
  1486.           by 20 degrees about the z axis.
  1487.  
  1488.           Remember: Left Handed Rotations.
  1489.  
  1490.           2.3.1.1.3 Scaling
  1491.  
  1492.           Scaling alters the size of an object by a given amount with
  1493.           respect to each of the coordinate axes.  The format of the
  1494.           declaration is:
  1495.  
  1496.              scale <xs, ys, zs>
  1497.  
  1498.           2.3.1.1.4 Shear
  1499.  
  1500.           A less frequently used, but occasionally useful transformation is
  1501.           linear shear.  Shear scales along one axis by an amount that is
  1502.           proportional to the location on another axis.  The format of the
  1503.           declaration is:
  1504.  
  1505.              shear yx, zx, xy, zy, xz, yz
  1506.  
  1507.           Typically only one or two of the components will be non-zero, for
  1508.           example the declaration:
  1509.  
  1510.              shear 0, 0, 1, 0, 0, 0
  1511.  
  1512.           will shear an object more and more to the right as y gets larger
  1513.           and larger.  The order of the letters in the declaration is
  1514.           descriptive, shear ... ab, ... means shear along direction a by
  1515.           the amount "ab" times the position b.
  1516.  
  1517.           This declaration should probably be split into three: one that
  1518.           associates shear in x with the y and z values, one that
  1519.           associates shear in y with x and z values, and one that
  1520.           associates shear in z with x and y values.
  1521.  
  1522.           You might want to look at the file "xander.pi" - this uses shear
  1523.           on boxes to make diagonally slanted parts of letters.
  1524.  
  1525.           2.3.1.2 Bounding box
  1526.  
  1527.           In order to speed up the process of determining if a ray
  1528.           intersects an object and in order to define good bounds for
  1529.           surfaces such as polynomials and implicit surfaces, a bounding
  1530.  
  1531.                                                                              27
  1532.  
  1533.  
  1534.           box can be specified.  A short example of how it is used to
  1535.           define bounds of a polynomial:
  1536.  
  1537.              define r0 3
  1538.              define r1 1
  1539.              define torus_expression (x^2 + y^2 + z^2 - (r0^2 + r1^2))^2 -
  1540.                                      4 * r0^2 * (r1^2 - z^2)
  1541.              object {
  1542.                 polynomial torus_expression
  1543.                 shiny_red
  1544.                 bounding_box <-(r0+r1), -(r0+r1), -r1>,
  1545.                              <(r0+r1), (r0+r1), r1>
  1546.                 }
  1547.  
  1548.           The test for intersecting a ray against a box is much faster than
  1549.           performing the test for the polynomial equation.  In addition the
  1550.           box helps the scan conversion process determine where to look for
  1551.           the surface of the torus.
  1552.  
  1553.           2.3.1.3 Subdivision of Primitives
  1554.  
  1555.           The amount of subdivision of a primitive that is performed before
  1556.           it is displayed as polygons is tunable.  These declarations only
  1557.           take effect during scan conversion - they are ignored during
  1558.           raytracing.  The two declarations are:
  1559.  
  1560.              u_steps n
  1561.              v_steps m
  1562.  
  1563.           Where U generally refers to the number of steps "around" the
  1564.           primitive (the number of steps around the equator of a sphere for
  1565.           example).  The parameter V refers to the number of steps along
  1566.           the primitive (latitudes on a sphere). Cone and cylinder
  1567.           primitives only require 1 step along V, but for smoothness may
  1568.           require many steps in U.
  1569.  
  1570.           For blobs, polynomials, and implicit surfaces, the v_steps
  1571.           component plays double duty, specifying how many subdivisions to
  1572.           perform along both the y-axis and the z-axis.
  1573.  
  1574.                                                                              28
  1575.  
  1576.  
  1577.  
  1578.           2.3.1.4 Shading Flags
  1579.  
  1580.           It is possible to tune the shading that will be performed for
  1581.           each object.  The values of each bit in the flag has the same
  1582.           meaning as that given for  global shading in section 1.7.1.4:
  1583.  
  1584.                1) Shadow_Check     Shadows will be generated
  1585.  
  1586.                2) Reflect_Check    Reflectivity will be tested
  1587.  
  1588.                4) Transmit_Check   Check for refraction
  1589.  
  1590.                8) Two_Sides        If on, highlighting will be performed on
  1591.                                    both sides of a surface.
  1592.  
  1593.                16) Cast_Shadow     Determines if an object can cast a
  1594.                                    shadow
  1595.  
  1596.                32) Primary_Rays    If off, then primary rays (those from
  1597.                                    the eye) are not checked against the
  1598.                                    object
  1599.  
  1600.  
  1601.           The declaration has the form:
  1602.  
  1603.              shading_flags xx
  1604.  
  1605.           i.e. if the value 50 is used for "xx" above, then this object can
  1606.           be reflective and will cast shadows, however there will be no
  1607.           tests for transparency and there will be no shading of the back
  1608.           sides of surfaces.
  1609.  
  1610.           Note: the shading flag only affects the object in which the
  1611.           declaration is made.  This means that if you want the shading
  1612.           values affected for all parts if a CSG object, then you will need
  1613.           a declaration in every component.
  1614.  
  1615.                                                                              29
  1616.  
  1617.  
  1618.  
  1619.           2.3.2 Primitives
  1620.  
  1621.           Primitives are the lowest level of shape description.  Typically
  1622.           a scene will contain many primitives, appearing either
  1623.           individually or as aggregates using either Constructive Solid
  1624.           Geometry (CSG) operations or gridded objects.
  1625.  
  1626.           The primitive shapes that can be used in Polyray include the
  1627.           following:
  1628.  
  1629.                o Bezier patch
  1630.  
  1631.                o Blob
  1632.  
  1633.                o Box
  1634.  
  1635.                o Cone
  1636.  
  1637.                o Cylinder
  1638.  
  1639.                o Disc
  1640.  
  1641.                o Implicit surface
  1642.  
  1643.                o Height field
  1644.  
  1645.                o Lathe surface
  1646.  
  1647.                o Parabola
  1648.  
  1649.                o Polygon
  1650.  
  1651.                o Polynomial surface
  1652.  
  1653.                o Sphere
  1654.  
  1655.                o Sweep surface
  1656.  
  1657.                o Torus
  1658.  
  1659.                o Triangular patch
  1660.  
  1661.  
  1662.           Descriptions of each of these primitive shapes, as well as
  1663.           references to data files that demonstrate them are given in the
  1664.           following subsections.  Following the description of the
  1665.           primitives are descriptions of how CSG and grids can be built.
  1666.  
  1667.                                                                              30
  1668.  
  1669.  
  1670.  
  1671.           2.3.2.1 Bezier patches
  1672.  
  1673.           A Bezier patch is a form of bicubic patch that interpolates its
  1674.           control vertices.  The patch is defined in terms of a 4x4 array
  1675.           of control vertices, as well as several tuning values.
  1676.  
  1677.           The format of the declaration is:
  1678.  
  1679.              bezier subdivision_type, flatness_value,
  1680.                     u_subdivisions, v_subdivision,
  1681.                     [ 16 comma-separated vertices, i.e.
  1682.                        <x0, y0, z0>, <x1, y1, z1>, ..., <x15, y15, z15> ]
  1683.  
  1684.           The subdivision type controls how the patch is represented
  1685.           internally.  The valid values and their meaning are:
  1686.  
  1687.                1) Store only the minimum information needed.  Least storage
  1688.                   requirement but takes more time during rendering.
  1689.  
  1690.                2) Store a hierarchical tree of bounding spheres that
  1691.                   contain smaller and smaller pieces of the patch.  This
  1692.                   tree is used during rendering to speed up the ray-
  1693.                   surface intersection process.  Faster but requires more
  1694.                   memory.
  1695.  
  1696.  
  1697.           The flatness value is used to determine how far a patch should be
  1698.           subdivided before it can be considered "flat".  The smaller this
  1699.           value, the more the patch will be subdivided (limited by the next
  1700.           two values).
  1701.  
  1702.           The number of levels of subdivision of the patch, in each
  1703.           direction, is controlled by the two parameters "u_subdivisions",
  1704.           and "v_subdivisions".  The more subdivisions allowed, the
  1705.           smoother the approximation to the patch, however storage and
  1706.           processing time go up.
  1707.  
  1708.           An example of a bezier patch is:
  1709.  
  1710.              object {
  1711.                 bezier 2, 0.05, 3, 3,
  1712.                    <0, 0, 2>, <1, 0, 0>, <2, 0, 0>, <3, 0,-2>,
  1713.                    <0, 1, 0>, <1, 1, 0>, <2, 1, 0>, <3, 1, 0>,
  1714.                    <0, 2, 0>, <1, 2, 0>, <2, 2, 0>, <3, 2, 0>,
  1715.                    <0, 3, 2>, <1, 3, 0>, <2, 3, 0>, <3, 3,-2>
  1716.              rotate <30, -70, 0>
  1717.              shiny_red
  1718.              }
  1719.  
  1720.  
  1721.                                                                              31
  1722.  
  1723.  
  1724.           Sample files: bezier0.pi, teapot.pi, teapot.inc
  1725.  
  1726.           2.3.2.2 Blob
  1727.  
  1728.           A blob describes a smooth potential field around one or more
  1729.           spherical, cylindrical, or planar components.
  1730.  
  1731.           The format of the declaration is:
  1732.  
  1733.              blob threshold:
  1734.                 blob_component1
  1735.                 [, blob_component2 ]
  1736.                 [, etc. for each component ]
  1737.  
  1738.           The threshold is the minimum potential value that will be
  1739.           considered when examining the interaction of the various
  1740.           components of the blob. Each blob component one of two forms:
  1741.  
  1742.              sphere <x, y, z>, strength, radius
  1743.              cylinder <x0, y0, z0>, <x1, y1, z1>, strength, radius
  1744.              plane <nx, ny, nz>, d, strength, dist
  1745.  
  1746.           The strength component describes how strong the potential field
  1747.           is around the center of the component, the "radius" component
  1748.           describes the maximum distance at which the component will
  1749.           interact with other components.  For a spherical blob component
  1750.           the vector <x,y,z> gives the center of the potential field around
  1751.           the component.  For a cylindrical blob component the vector <x0,
  1752.           y0, z0> defines one end of the axis of a cylinder, the vector
  1753.           <x1, y1, z1> defines the other end of the axis of a cylinder.  A
  1754.           planar blob component is defined by the standard plane equation
  1755.           with <nx, ny, nz> defining the normal and "d" defining the
  1756.           distance of the plane from the origin along the normal.
  1757.  
  1758.           Note: The ends of a cylindrical blob component are given
  1759.           hemispherical caps.
  1760.  
  1761.           Note: The colon and the commas in the declaration really are
  1762.           important.
  1763.  
  1764.  
  1765.           An example of a blob is:
  1766.  
  1767.           object {
  1768.                 blob 0.5:
  1769.                    cylinder <0,  0, 0>, <5, 0, 0>, 1, 0.7,
  1770.                    cylinder <1, -3, 0>, <3, 2, 0>, 1, 1.4,
  1771.                    sphere <3, -0.8, 0>, 1, 1,
  1772.                    sphere <4,  0.5, 0>, 1, 1,
  1773.                    sphere <1,  1,   0>, 1, 1,
  1774.  
  1775.                                                                              32
  1776.  
  1777.  
  1778.                    sphere <1,  1.5, 0>, 1, 1,
  1779.                    sphere <1,  2.7, 0>, 1, 1
  1780.  
  1781.                 texture {
  1782.                    surface {
  1783.                       color red
  1784.                       ambient 0.2
  1785.                       diffuse 0.8
  1786.                       specular white, 1
  1787.                       microfacet Phong 5
  1788.                       }
  1789.                    }
  1790.              }
  1791.  
  1792.           Note: since a blob is essentially a collection of 4th order
  1793.           polynomials, it is possible to specify which quartic root solver
  1794.           to use.  See section 2.3.2.12, "Polynomial surface" for a
  1795.           description of the "root_solver" statement.
  1796.  
  1797.           Sample file: blob.pi
  1798.  
  1799.           2.3.2.3 Box
  1800.  
  1801.           A box is rectangular solid that has its edges aligned with the x,
  1802.           y, and z axes.  it is defined in terms of two diagonally opposite
  1803.           corners.  The alignment can be changed by rotations after the
  1804.           shape declaration.
  1805.  
  1806.           The format of the declaration is:
  1807.  
  1808.              box <x0, y0, z0>, <x1, y1, z1>
  1809.  
  1810.           Usually the convention is that the first point is the front-lower-
  1811.           left point and the second is the back-upper-right point.  The
  1812.           following declaration is four boxes stacked on top of each other:
  1813.  
  1814.              define pyramid
  1815.              object {
  1816.                   object { box <-1, 3, -1>, <1, 4, 1> }
  1817.                 + object { box <-2, 2, -2>, <2, 3, 2> }
  1818.                 + object { box <-3, 1, -3>, <3, 2, 3> }
  1819.                 + object { box <-4, 0, -4>, <4, 1, 4> }
  1820.                 matte_blue
  1821.                 }
  1822.  
  1823.           Sample file: boxes.pi
  1824.  
  1825.                                                                              33
  1826.  
  1827.  
  1828.  
  1829.           2.3.2.4 Cone
  1830.  
  1831.           A cone is defined in terms of a base point, an apex point, and
  1832.           the radii at those two points.  Note that cones are not closed.
  1833.  
  1834.           The format of the declaration is:
  1835.  
  1836.              cone <x0, y0, z0>, r0, <x1, y1, z1>, r1
  1837.  
  1838.           An example declaration of a cone is:
  1839.  
  1840.                object {
  1841.                   cone <0, 0, 0>, 4, <4, 0, 0>, 0
  1842.                   shiny_red
  1843.                   }
  1844.  
  1845.           Sample file: cone.pi, cones.pi
  1846.  
  1847.           2.3.2.5 Cylinder
  1848.  
  1849.           A cylinder is defined in terms of a bottom point, a top point,
  1850.           and its radius.  Note that cylinders are not closed.
  1851.  
  1852.           The format of the declaration is:
  1853.  
  1854.              cylinder <x0, y0, z0>, <x1, y1, z1>, r
  1855.  
  1856.           An example of a cylinder is:
  1857.  
  1858.              object {
  1859.                 cylinder <-3, -2, 0>, <0, 1, 3>, 0.5
  1860.                 shiny_red
  1861.                 }
  1862.  
  1863.           Sample file: cylinder.pi
  1864.  
  1865.           2.3.2.6 Disc
  1866.  
  1867.           A disc is defined in terms of a center a normal and either a
  1868.           radius, or using an inner radius and an outer radius.  If only
  1869.           one radius is given, then the disc has the appearance of a (very)
  1870.           flat coin.  If two radii are given, then the disc takes the shape
  1871.           of an annulus (washer) where the disc extends from the first
  1872.           radius to the second radius.  Typical uses for discs are as caps
  1873.           for cones and cylinders, or as ground planes (using a really big
  1874.           radius).
  1875.  
  1876.           The format of the declaration is:
  1877.  
  1878.  
  1879.                                                                              34
  1880.  
  1881.  
  1882.              disc <cx, cy, cz>, <nx, ny, nz>, r
  1883.           or
  1884.              disc <cx, cy, cz>, <nx, ny, nz>, ir, or
  1885.  
  1886.           The center vector <cx,cy,cz> defines where the center of the disc
  1887.           is located, the normal vector <nx,ny,nz> defines the direction
  1888.           that is perpendicular to the disc.  i.e. a disc having the center
  1889.           <0,0,0> and the normal <0,1,0> would put the disc in the x-z
  1890.           plane with the y-axis coming straight out of the center.
  1891.  
  1892.           An example of a disc is:
  1893.  
  1894.              object {
  1895.                 disc <0, 2, 0>, <0, 1, 0>, 3
  1896.                 rotate <-30, 20, 0>
  1897.                 shiny_red
  1898.                 }
  1899.  
  1900.           Note: a disc is infinitely thin.  If you look at it edge-on it
  1901.           will disappear.
  1902.  
  1903.           Sample file: disc.pi
  1904.  
  1905.           2.3.2.7 Implicit Surface
  1906.  
  1907.           The format of the declaration is:
  1908.  
  1909.              function f(x,y,z)
  1910.  
  1911.           The function f(x,y,z) may be any algebraic expression composed of
  1912.           the variables: x, y, z, a numerical value (i.e. 0.5), the
  1913.           operators: +, -, *, /, ^, and the functions:  cos, cosh, exp,
  1914.           fabs, ln, log, sin, sinh, tan, tanh.  The code is not
  1915.           particularly fast, not is it totally accurate, however the
  1916.           capability to ray-trace such a wide class of functions by a SW
  1917.           program is (I believe) unique to Polyray.
  1918.  
  1919.           The distance along the ray that solutions will be found in are
  1920.           determined by the following:
  1921.  
  1922.                o  If there is a bounding box, then the entry and exit
  1923.                   points of the ray with the box will be used as the
  1924.                   search interval.
  1925.  
  1926.                o  If there is no bounding box then the interval from 0.01
  1927.                   to 100 will be used.
  1928.  
  1929.                o  Solutions must be more than 1.0e-4 units distant from
  1930.                   each other.
  1931.  
  1932.  
  1933.                                                                              35
  1934.  
  1935.  
  1936.  
  1937.           Note: the absolute value can be written with vertical bars, i.e.
  1938.           |x|^0.75.
  1939.  
  1940.           The following object is taken from "sombrero.pi" and is a surface
  1941.           that looks very much like diminishing ripples on the surface of
  1942.           water.
  1943.  
  1944.              define a_const 1.0
  1945.              define b_const 2.0
  1946.              define c_const 3.0
  1947.              define two_pi_a 2.0 * 3.14159265358 * a_const
  1948.  
  1949.              // Define a diminishing cosine surface (sombrero)
  1950.              object {
  1951.                 function y - c_const * cos(two_pi_a * sqrt(x^2 + z^2)) *
  1952.                                        exp(-b_const * sqrt(x^2 + z^2))
  1953.                 matte_red
  1954.                 bounds object { box <-4, -4, -4>, <4, 4, 4> }
  1955.                 }
  1956.  
  1957.           Sample files: sinsurf.pi, sectorl.pi, sombrero.pi, superq.pi,
  1958.           zonal.pi
  1959.  
  1960.           2.3.2.8 Height Field
  1961.  
  1962.           There are two ways that height fields can be specified, either by
  1963.           using data stored in a Targa file, or using an implicit function
  1964.           of the form y = f(x, z).
  1965.  
  1966.           The default orientation of a height field is that the entire
  1967.           field lies in the square 0 <= x <= 1, 0 <= z <= 1.  File based
  1968.           height fields are always in this orientation, implicit height
  1969.           fields can optionally be defined over a different area of the x-z
  1970.           plane.  The height value is used for y.
  1971.  
  1972.           2.3.2.8.1 File Based Height Fields
  1973.  
  1974.           Height fields data can be read from a Targa format file.  The
  1975.           only formats currently supported are 8, 16 and 24 bit
  1976.           uncompressed.
  1977.  
  1978.           By using "smooth_" in front of the declaration, an extra step is
  1979.           performed that calculates normals to the height field at every
  1980.           point within the field.  The result of this is a greatly smoothed
  1981.           appearance, at the expense of around three times as much memory
  1982.           being used.
  1983.  
  1984.           The format of the declaration is:
  1985.  
  1986.  
  1987.                                                                              36
  1988.  
  1989.  
  1990.              height_field "filename"
  1991.              smooth_height_field "filename"
  1992.  
  1993.           The sample program "wake.c" generates a Targa file that simulates
  1994.           the wake behind a boat.
  1995.  
  1996.           Sample file: wake.pi (requires that "wave.tga" be generated by
  1997.           "wake.c")
  1998.  
  1999.           The way the pixel values of the file are interpreted are:
  2000.  
  2001.           2.3.2.8.1.1 8 Bit Format
  2002.  
  2003.           Each pixel in the file (Type 3 Targa, raw greyscale image) is
  2004.           represented by a single byte.  The byte is treated as a signed
  2005.           integer, giving a range of values from -127 to 127.
  2006.  
  2007.           If you are generating a Targa file to use in Polyray, given a
  2008.           height, add 128 to the height and write it as an unsigned char.
  2009.           The following code fragment shows what the statement would look
  2010.           like.
  2011.  
  2012.                    float height;
  2013.                    FILE *height_file;
  2014.  
  2015.                    ... calculate each eight ...
  2016.  
  2017.                    fputc((unsigned char)(height += 128.0), height_file);
  2018.  
  2019.  
  2020.  
  2021.           2.3.2.8.1.2 16 Bit Format
  2022.  
  2023.           Each pixel in the file (Type 1 or type 2 Targa) is represented by
  2024.           two bytes, low then high.  The high component defines the integer
  2025.           component of the height, the low component holds the fractional
  2026.           part scaled by 255. The entire value is offset by 128 to
  2027.           compensate for the unsigned nature of the storage bytes.  As an
  2028.           example the values  high = 140, low = 37 would be translated to
  2029.           the height:
  2030.  
  2031.              (140 + 37 / 256) - 128 = 12.144
  2032.  
  2033.           similarly if you are generating a Targa file to use in Polyray,
  2034.           given a height, add 128 to the height, extract the integer
  2035.           component, then extract the scaled fractional component.  The
  2036.           following code fragment shows a way of generating the low and
  2037.           high bytes from a floating point number.
  2038.  
  2039.                    unsigned char low, high;
  2040.  
  2041.                                                                              37
  2042.  
  2043.  
  2044.                    float height;
  2045.                    FILE *height_file;
  2046.  
  2047.                    ...
  2048.  
  2049.                    height += 128.0;
  2050.                    high = (unsigned char)height;
  2051.                    height -= (float)high;
  2052.                    low = (unsigned char)(256.0 * height);
  2053.                    fputc(low, height_file);
  2054.                    fputc(high, height_file);
  2055.  
  2056.  
  2057.  
  2058.           2.3.2.8.1.3 24 Bit Format
  2059.  
  2060.           The red component defines the integer component of the height,
  2061.           the green component holds the fractional part scaled by 255, the
  2062.           blue component is ignored.  The entire value is offset by 128 to
  2063.           compensate for the unsigned nature of the RGB  values.  As an
  2064.           example the values  r = 140, g = 37, and b = 0 would be
  2065.           translated to the height:
  2066.  
  2067.              (140 + 37 / 256) - 128 = 12.144
  2068.  
  2069.           similarly if you are generating a Targa file to use in Polyray,
  2070.           given a height, add 128 to the height, extract the integer
  2071.           component, then extract the scaled fractional component.  The
  2072.           following code fragment shows a way of generating the RGB
  2073.           components from a floating point number.
  2074.  
  2075.                    unsigned char r, g, b;
  2076.                    float height;
  2077.                    FILE *height_file;
  2078.  
  2079.                    ...
  2080.  
  2081.                    height += 128.0;
  2082.                    r = (unsigned char)height;
  2083.                    height -= (float)r;
  2084.                    g = (unsigned char)(256.0 * height);
  2085.                    b = 0;
  2086.                    fputc(b, height_file);
  2087.                    fputc(g, height_file);
  2088.                    fputc(r, height_file);
  2089.  
  2090.  
  2091.           2.3.2.8.2 Implicit Height Fields
  2092.  
  2093.           Another way to define height fields is by evaluating a
  2094.  
  2095.                                                                              38
  2096.  
  2097.  
  2098.           mathematical function over a grid.  Given a function y = f(x, z),
  2099.           Polyray will evaluate the function over a specified area and
  2100.           generate a height field based on the function.  This method can
  2101.           be used to generate images of many sorts of functions that are
  2102.           not easily represented by collections of simpler primitives.
  2103.  
  2104.           The valid formats of the declaration are:
  2105.  
  2106.              height_fn xsize, zsize, min_x, max_x, min_z, max_z, expression
  2107.              height_fn xsize, zsize, expression
  2108.              smooth_height_fn xsize, zsize, min_x, max_x, min_z, max_z,
  2109.                               expression
  2110.              smooth_height_fn xsize, zsize, expression
  2111.  
  2112.           If the four values min_x, max_x, min_z, and max_z are not defined
  2113.           then the default square 0 <= x <= 1, 0 <= z <= 1 will be used.
  2114.  
  2115.           For example,
  2116.  
  2117.              // Define constants for the sombrero function
  2118.              define a_const 1.0
  2119.              define b_const 2.0
  2120.              define c_const 3.0
  2121.              define two_pi_a 2.0 * 3.14159265358 * a_const
  2122.  
  2123.              // Define a diminishing cosine surface (sombrero)
  2124.              object {
  2125.                 height_fn 80, 80, -4, 4, -4, 4,
  2126.                    c_const * cos(two_pi_a * sqrt(x^2 + z^2)) *
  2127.                              exp(-b_const * sqrt(x^2 + z^2))
  2128.                 shiny_red
  2129.                 }
  2130.  
  2131.           will build a height field 80x80, covering the area from -4 <= x
  2132.           <= 4, and -4 <= z <= 4.
  2133.  
  2134.           Compare the run-time performance and visual quality of the
  2135.           sombrero function as defined in "sombfn.pi" with the sombrero
  2136.           function as defined in "sombrero.pi".  The former uses a height
  2137.           field representation and renders quite fast.  The latter uses a
  2138.           very general function representation and gives smoother but very
  2139.           slow results.
  2140.  
  2141.           Sample file: sombfn.pi, sinfn.pi
  2142.  
  2143.           2.3.2.9 Lathe surfaces
  2144.  
  2145.           A lathe surface is a polygon that has been revolved about the y-
  2146.           axis.  This surface allows you to build objects that are
  2147.  
  2148.                                                                              39
  2149.  
  2150.  
  2151.           symmetric about an axis, simply by defining 2D points.
  2152.  
  2153.           The format of the declaration is:
  2154.  
  2155.               lathe type, direction, total_vertices,
  2156.                  <vert1.x,vert1.y,vert1.z>
  2157.                  [, <vert2.x, vert2.y, vert2.z>]
  2158.                  [, etc. for total_vertices vertices]
  2159.  
  2160.           The value of "type" is either 1, or 2.  If the value is 1, then
  2161.           the surface will simply revolve the line segments.  If the value
  2162.           is 2, then the surface will be represented by a spline that
  2163.           approximates the line segments that were given.  A lathe surface
  2164.           of type 2 is a very good way to smooth off corners in a set of
  2165.           line segments.
  2166.  
  2167.           The value of the vector "direction" is used to change the
  2168.           orientation of the lathe.  For a lathe surface that goes straight
  2169.           up and down the y-axis, use <0, 1, 0> for "direction.  For a
  2170.           lathe surface that lies on the x-axis, you would use <1, 0, 0>
  2171.           for the direction.
  2172.  
  2173.           Sample file: lathe1.pi, lathe2.pi
  2174.  
  2175.           Note that CSG will really only work correctly if you close the
  2176.           lathe - that is either make the end point of the lathe the same
  2177.           as the start point, or make the x-value of the start and end
  2178.           points equal zero.  Lathes, unlike polygons are not automatically
  2179.           closed by Polyray.
  2180.  
  2181.           Note: since a splined lathe surface (type = 2) is a 4th order
  2182.           polynomial, it is possible to specify which quartic root solver
  2183.           to use.  See section 2.3.2.12, "Polynomial surface" for a
  2184.           description of the "root_solver" statement.
  2185.  
  2186.           2.3.2.10 Parabola
  2187.  
  2188.           A parabola is defined in terms of a bottom point, a top point,
  2189.           and its radius at the top.
  2190.  
  2191.           The format of the declaration is:
  2192.  
  2193.              parabola <x0, y0, z0>, <x1, y1, z1>, r
  2194.  
  2195.           The vector <x0,y0,z0> defines the "top" of the parabola - the
  2196.           part that comes to a point.  The vector <x1,y1,z1> defines the
  2197.           "bottom" of the parabola, the width of the parabola at this point
  2198.           is "r".
  2199.  
  2200.           An example of a parabola declaration is:
  2201.  
  2202.                                                                              40
  2203.  
  2204.  
  2205.  
  2206.              object {
  2207.                 parabola <0, 6, 0>, <0, 0, 0>, 3
  2208.                 translate <16, 0, 16>
  2209.                 steel_blue
  2210.                 }
  2211.  
  2212.           This is sort of like a salt shaker shape with a rounded top and
  2213.           the base on the x-z plane.
  2214.  
  2215.           2.3.2.11 Polygon
  2216.  
  2217.           Although polygons are not very interesting mathematically, there
  2218.           are many sorts of objects that are much easier to represent with
  2219.           polygons.  Polyray assumes that all polygons are closed and
  2220.           automatically adds a side from the last vertex to the first
  2221.           vertex.
  2222.  
  2223.           The format of the declaration is:
  2224.  
  2225.               polygon total_vertices,
  2226.                  <vert1.x,vert1.y,vert1.z>
  2227.                  [, <vert2.x, vert2.y, vert2.z>]
  2228.                  [, etc. for total_vertices vertices]
  2229.  
  2230.           As with the sphere, note the comma separating each vertex of the
  2231.           polygon.
  2232.  
  2233.           I use polygons as a floor in a lot of images.  They are a little
  2234.           slower than the corresponding plane, but for scan conversion they
  2235.           are a lot easier to handle.  An example of a checkered floor made
  2236.           from a polygon is:
  2237.  
  2238.              object {
  2239.                 polygon 4, <-20, 0, -20>, <-20, 0,  20>,
  2240.                            < 20, 0,  20>, < 20, 0, -20>
  2241.                 texture {
  2242.                    checker matte_white, matte_black
  2243.                    translate <0, -0.1, 0>
  2244.                    scale <2, 1, 2>
  2245.                    }
  2246.                 }
  2247.  
  2248.           2.3.2.12 Polynomial surface
  2249.  
  2250.           The format of the declaration is:
  2251.  
  2252.              polynomial f(x,y,z)
  2253.  
  2254.           The function f(x,y,z) must be a simple polynomial, i.e.
  2255.  
  2256.                                                                              41
  2257.  
  2258.  
  2259.           x^2+y^2+z^2-1.0 is the definition of a sphere of radius 1
  2260.           centered at (0,0,0).  See section 4.1 for a little more detail on
  2261.           restrictions on the form of the polynomial.
  2262.  
  2263.           For quartic equations, there are three available ways to solve
  2264.           for roots, by specifying which one is desired, it is possible to
  2265.           tune for quality or speed.  The method of Ferrari is the fastest,
  2266.           but also the most numerically unstable.  By default the method of
  2267.           Vieta is used.  Sturm sequences (which are the slowest) should be
  2268.           used where the highest quality is desired.
  2269.  
  2270.           The declaration of which root solver to use takes one of the
  2271.           forms:
  2272.  
  2273.              root_solver Ferrari
  2274.              root_solver Vieta
  2275.              root_solver Sturm
  2276.  
  2277.           (Capitalization is important - these are proper nouns after all.)
  2278.  
  2279.           Note: due to unavoidable numerical inaccuracies, not all
  2280.           polynomial surfaces will render correctly from all directions.
  2281.  
  2282.           The following example, taken from "devil.pi" defines a quartic
  2283.           polynomial.  The use of the CSG clipping object is to trim
  2284.           uninteresting parts of the surface.  The bounding box declaration
  2285.           helps the scan conversion routines figure out where to look for
  2286.           the surface.
  2287.  
  2288.              // Variant of a devil's curve in 3-space.  This figure has a
  2289.              // top and bottom part that are very similar to a hyperboloid
  2290.              // of one sheet, however the central region is pinched in the
  2291.              // middle leaving two teardrop shaped holes.
  2292.              object {
  2293.                   object {
  2294.                      polynomial x^4 + 2*x^2*z^2 - 0.36*x^2 - y^4 +
  2295.                                 0.25*y^2 + z^4
  2296.                      root_solver Ferrari
  2297.                      }
  2298.                 & object { box <-2, -2, -0.5>, <2, 2, 0.5> }
  2299.                 bounding_box <-2, -2, -0.5>, <2, 2, 0.5>
  2300.                 rotate <10, 20, 0>
  2301.                 translate <0, 3, -10>
  2302.                 shiny_red
  2303.                 }
  2304.  
  2305.           Note: as the order of the polynomial goes up, the numerical
  2306.           accuracy required to render the surface correctly also goes up.
  2307.           One problem that starts to rear its ugly head starting at around
  2308.           3rd to 4th order equations is a problem with determining shadows
  2309.  
  2310.                                                                              42
  2311.  
  2312.  
  2313.           correctly.  The result is black spots on the surface.  You can
  2314.           ease this problem to a certain extent by making the value of
  2315.           "shadow_tolerance" larger.  For 4th and higher equations, you
  2316.           will want to use a value of at least 0.05, rather than the
  2317.           default 0.001.
  2318.  
  2319.           Sample file: torus.pi, many others
  2320.  
  2321.           2.3.2.13 Spheres
  2322.  
  2323.           Spheres are the simplest 3D object to render and a sphere
  2324.           primitive enjoys a speed advantage over most other primitives.
  2325.  
  2326.           The format of the declaration is:
  2327.  
  2328.               sphere <center.x, center.y, center.z>, radius
  2329.  
  2330.           Note the comma after the center vector, it really is necessary.
  2331.  
  2332.           My basic benchmark file is a single sphere, illuminated by a
  2333.           single light.  The definition of the sphere is:
  2334.  
  2335.              object {
  2336.                 sphere <0, 0, 0>, 2
  2337.                 shiny_red
  2338.                 }
  2339.  
  2340.           Sample file: sphere.pi
  2341.  
  2342.           2.3.2.14 Sweep surface
  2343.  
  2344.           A sweep surface, also referred to as an extruded surface, is a
  2345.           polygon that has been swept along a given direction.  It can be
  2346.           used to make multi-sided beams, or to create ribbon-like objects.
  2347.  
  2348.           The format of the declaration is:
  2349.  
  2350.               sweep type, direction, total_vertices,
  2351.                  <vert1.x,vert1.y,vert1.z>
  2352.                  [, <vert2.x, vert2.y, vert2.z>]
  2353.                  [, etc. for total_vertices vertices]
  2354.  
  2355.           The value of "type" is either 1, or 2.  If the value is 1, then
  2356.           the surface will be a set of connected squares.  If the value is
  2357.           2, then the surface will be represented by a spline that
  2358.           approximates the line segments that were given.
  2359.  
  2360.           The value of the vector "direction" is used to change the
  2361.           orientation of the sweep.  For a sweep surface that is extruded
  2362.           straight up and down the y-axis, use <0, 1, 0> for "direction.
  2363.  
  2364.                                                                              43
  2365.  
  2366.  
  2367.           The size of the vector "direction" will also affect the amount of
  2368.           extrusion, i.e. if |direction| = 2, then the extrusion will be
  2369.           two units in that direction.
  2370.  
  2371.           An example of a sweep surface is:
  2372.  
  2373.              // Sweep made from connected quadratic splines.
  2374.              object {
  2375.                 sweep 2, <0, 2, 0>, 16,
  2376.                    <0, 0>, <0, 1>, <-1, 1>, <-1, -1>, <2, -1>, <2, 3>,
  2377.                    <-4, 3>, <-4, -4>, <4, -4>, <4, -11>, <-2, -11>,
  2378.                    <-2, -7>, <2, -7>, <2, -9>, <0, -9>, <0, -8>
  2379.                 translate <0, 0, -4>
  2380.                 scale <1, 0.5, 1>
  2381.                 rotate <0,-45, 0>
  2382.                 translate <10, 0, -18>
  2383.                 shiny_yellow
  2384.                 }
  2385.  
  2386.  
  2387.           Sample file: sweep1.pi, sweep2.pi
  2388.  
  2389.           Note that CSG will really only work correctly if you close the
  2390.           sweep - that is make the end point of the sweep the same as the
  2391.           start point.  Sweeps, unlike polygons are not automatically
  2392.           closed by Polyray.
  2393.  
  2394.           2.3.2.15 Torus
  2395.  
  2396.           The torus primitive is a doughnut shaped surface that is defined
  2397.           by a center point, the distance from the center point to the
  2398.           middle of the ring of the doughnut, the radius of the ring of the
  2399.           doughnut, and the orientation of the surface.
  2400.  
  2401.           The format of the declaration is:
  2402.  
  2403.               torus r0, r1, <center.x, center.y, center.z>,
  2404.                 <dir.x, dir.y, dir.z>
  2405.  
  2406.  
  2407.           As an example, a torus that has major radius 1, minor radius 0.4,
  2408.           and is oriented so that the ring lies in the x-z plane would be
  2409.           declared as:
  2410.  
  2411.              object {
  2412.                 torus 1, 0.4, <0, 0, 0>, <0, 1, 0>
  2413.                 shiny_red
  2414.                 }
  2415.  
  2416.           Note: since a torus is a 4th order polynomial, it is possible to
  2417.  
  2418.                                                                              44
  2419.  
  2420.  
  2421.           specify which quartic root solver to use.  See section 2.3.2.12,
  2422.           "Polynomial surface" for a description of the "root_solver"
  2423.           statement.
  2424.  
  2425.           Sample file: torus.pi
  2426.  
  2427.           2.3.2.16 Triangular patches
  2428.  
  2429.           A triangular patch is defined by a set of vertices and their
  2430.           normals. When calculating shading information for a triangular
  2431.           patch, the normal information is used to interpolate the final
  2432.           normal from the intersection point to produce a smooth shaded
  2433.           triangle.
  2434.  
  2435.           The format of the declaration is:
  2436.  
  2437.               patch <vert1.x,vert1.y,vert1.z>, <norm1.x,norm1.y,norm1.z>,
  2438.                     <vert2.x,vert2.y,vert2.z>, <norm2.x,norm2.y,norm2.z>,
  2439.                     <vert3.x,vert3.y,vert3.z>, <norm3.x,norm3.y,norm3.z>
  2440.  
  2441.           Smooth patch data is usually generated as the output of another
  2442.           program.
  2443.  
  2444.           2.3.3 Constructive Solid Geometry (CSG)
  2445.  
  2446.           Objects can be defined in terms of the union, intersection, and
  2447.           inverse of other objects.  The operations and the symbols used
  2448.           are:
  2449.  
  2450.              csgexper + csgexper  - Union
  2451.              csgexper * csgexper  - Intersection
  2452.              csgexper - csgexper  - Difference
  2453.              csgexper & csgexper  - Clip the first object by the second
  2454.              ~csgexper            - Inverse
  2455.              (csgexper)           - Parenthesised expression
  2456.  
  2457.           Union simply collects two objects together.  Union is a
  2458.           convienient way to group objects in such a way as to be able to
  2459.           transform them as a group.  Intersection keeps only those parts
  2460.           of each object that are "inside" the other object.  Difference
  2461.           keeps all parts of the two surfaces that are inside the first
  2462.           object and outside the second.  Clipping removes all parts of the
  2463.           first object that are outside the second.  The inverse operation
  2464.           inverts the "inside" to be the outside and vice-versa.  (i.e. a -
  2465.           b is the same as a * ~b).
  2466.  
  2467.                                                                              45
  2468.  
  2469.  
  2470.  
  2471.           Note that intersection and difference require a clear inside and
  2472.           outside.  Not all primitives have well defined sides.  Those that
  2473.           do are:
  2474.  
  2475.              Spheres, Boxes, Polynomials, Blobs, and Functions.
  2476.  
  2477.           Other surfaces that do not always have a clear inside/outside,
  2478.           but work reasonably well in CSG intersections are: Cylinders,
  2479.           Cones, Discs, Lathes, Parabola, Polygons, and Sweeps.
  2480.  
  2481.           Using Cylinders, Cones, and Parabolas works correctly, but the
  2482.           open ends of these surfaces will also be open in the resulting
  2483.           CSG.  To close them off you can use a disc shape.
  2484.  
  2485.           Using Discs, and Polygons in a CSG is really the same as doing a
  2486.           CSG with the plane that they lie in.  If fact, a large disc is an
  2487.           excellent choice for clipping or intersecting an object, as the
  2488.           inside/outside test is very fast.
  2489.  
  2490.           Lathes, and Sweeps use Jordan's rule to determine if a point is
  2491.           inside.  This means that given a test point, if a line from that
  2492.           point to infinity crosses the surface an odd number of times,
  2493.           then the point is inside.  The net result is that if the lathe
  2494.           (or sweep) is not closed, then you may get odd results in a CSG
  2495.           intersection (or difference).
  2496.  
  2497.           Height fields don't work well with CSG.
  2498.  
  2499.           As an example, the following file will generate a view of a
  2500.           sphere of radius 1 with a hole of radius 0.5 through the middle:
  2501.  
  2502.              viewpoint {
  2503.                 from <0,0,-8>
  2504.                 at <0,0,0>
  2505.                 up <0,1,0>
  2506.                 angle 30
  2507.                 resolution 160, 160
  2508.                 }
  2509.  
  2510.              background white
  2511.              light <0, 20, -40>
  2512.  
  2513.              include "colors.inc"
  2514.  
  2515.              define cylinder_z object { cylinder <0,0,-2>, <0,0,2>, 0.5 }
  2516.              define unit_sphere object { sphere <0,0,0>, 1 }
  2517.  
  2518.              // Define a CSG shape by deleting a cylinder from a sphere
  2519.              object {
  2520.  
  2521.                                                                              46
  2522.  
  2523.  
  2524.                 unit_sphere { shiny_red } - cylinder_z { shiny_yellow }
  2525.                 rotate <0, 20, 0>
  2526.                 }
  2527.  
  2528.           Sample files: lens.pi, polytope.pi
  2529.  
  2530.           2.3.4 Gridded objects
  2531.  
  2532.           A gridded object is a way to compactly represent a rectangular
  2533.           arrangement of objects by using an image map.  Each object is
  2534.           placed within a 1x1 cube that has its lower left corner at the
  2535.           location <i, 0, j> and its upper right corner at <i+1, 1, j+1>.
  2536.           The color index of each pixel in the image map is used to
  2537.           determine which of a set of objects will be placed at the
  2538.           corresponding position in space.
  2539.  
  2540.           The gridded object is much faster to render than the
  2541.           corresponding layout of objects.  The major drawback is that
  2542.           every object must be scaled and translated to completely fit into
  2543.           a 1x1x1 cube that has corners at <0,0,0> and <1,1,1>.
  2544.  
  2545.           The size of the entire grid is determined by the number of pixels
  2546.           in the image.  A 16x32 image would go from 0 to 16 along the x-
  2547.           axis and the last row would range from 0 to 16 at 31 units in z
  2548.           out from the x-axis.
  2549.  
  2550.           The format of the declaration is:
  2551.  
  2552.              gridded "image.tga",
  2553.                 object1
  2554.                 object2
  2555.                 object3
  2556.                 ...
  2557.  
  2558.           An example of how a gridded object is declared is:
  2559.  
  2560.              define tiny_sphere object { sphere <0.5, 0.4, 0.5>, 0.4 }
  2561.              define pointy_cone object { cone <0.5, 0.5, 0.5>, 0.4,
  2562.                                         <0.5, 1, 0.5>, 0 }
  2563.  
  2564.              object {
  2565.                 gridded "grdimg0.tga",
  2566.                    tiny_sphere { shiny_coral }
  2567.                    tiny_sphere { shiny_red }
  2568.                    pointy_cone { shiny_green }
  2569.                 translate <-10, 0, -10>
  2570.                 rotate <0, 210, 0>
  2571.                 }
  2572.  
  2573.           In the image "grdimg0.tga", there are a total of 3 colors used,
  2574.  
  2575.                                                                              47
  2576.  
  2577.  
  2578.           every pixel that uses color index 0 will generate a shiny "coral"
  2579.           colored sphere, every pixel that uses index  will generate a red
  2580.           sphere, every pixel that uses index 2 will generate a green cone,
  2581.           and every other color index used in the image will leave the
  2582.           corresponding space empty.
  2583.  
  2584.           Sample files: grid.pi, river.pi
  2585.  
  2586.           2.3.5 Bounding Slabs
  2587.  
  2588.           Bounding slabs are used by Polyray to  sort the objects in the
  2589.           scene along the coordinate axes.  For scenes with many objects,
  2590.           the result is often greatly reduced rendering times over a non-
  2591.           optimized renderer.
  2592.  
  2593.           This sorting operation can lead to the generation of many new
  2594.           objects that will contain the ones defined in the data file.
  2595.  
  2596.           Bounding slabs work best when there are many small objects, and
  2597.           when the objects are oriented in such a way that they can be
  2598.           separated by the slabs.
  2599.  
  2600.           2.4 Color and lighting
  2601.  
  2602.           The color space used in polyray is RGB, with values of each
  2603.           component specified as a value from 0 -> 1.  The way the color
  2604.           and shading of surfaces is specified is described in the
  2605.           following sections.
  2606.  
  2607.           RGB colors are defined as either a three component vector, such
  2608.           as <0.6, 0.196078, 0.8>, or as one of the X11R3 named colors
  2609.           (which for the value given is DarkOrchid).  One of these days
  2610.           when I feel like typing and not thinking (or if I find them on
  2611.           line), I'll put in the X11R4 colors.
  2612.  
  2613.           The coloring of objects is determined by the interaction of
  2614.           lights, the shape of the surface it is striking, and the
  2615.           characteristics of the surface itself.
  2616.  
  2617.           2.4.1 Light sources
  2618.  
  2619.           Light sources are one of: simple positional light sources, spot
  2620.           lights, or textured lights.  None of these lights have any
  2621.           physical size.  The lights do not appear in the scene, only the
  2622.           effects of the lights.
  2623.  
  2624.                                                                              48
  2625.  
  2626.  
  2627.  
  2628.           2.4.1.1 Positional Lights
  2629.  
  2630.           A positional light is defined by its RGB color and its XYZ
  2631.           position.
  2632.  
  2633.           The format of the declaration is:
  2634.  
  2635.               light color, location
  2636.               light location
  2637.  
  2638.           The second declaration will use white as the color.
  2639.  
  2640.           2.4.1.2 Spot Lights
  2641.  
  2642.           The format of the declaration is:
  2643.  
  2644.               spot_light color, location, pointed_at, Tightness, Angle,
  2645.           Falloff
  2646.               spot_light location, pointed_at
  2647.  
  2648.           The vector "location" defines the position of the spot light, the
  2649.           vector "pointed_at" defines the point at which the spot light is
  2650.           directed.  The optional components are:
  2651.  
  2652.             Color            The color of the spotlight
  2653.  
  2654.             Tightness        The power function used to determine the
  2655.                               shape of the hot spot
  2656.  
  2657.             Angle            The angle (in degrees) of the full effect of
  2658.                               the spot light
  2659.  
  2660.             Falloff          A larger angle at which the amount of light
  2661.                               falls to nothing
  2662.  
  2663.           A sample declaration is:
  2664.  
  2665.              spot_light white, <10,10,0>, <3,0,0>, 3, 5, 20
  2666.  
  2667.           Sample file: spot0.pi, spot1.pi
  2668.  
  2669.                                                                              49
  2670.  
  2671.  
  2672.  
  2673.           2.4.1.3 Textured lights
  2674.  
  2675.           Textured lights are an extension of point lights that use a
  2676.           function (including image maps) to describe the intensity & color
  2677.           of the light in each direction.  The format of the declaration
  2678.           is:
  2679.  
  2680.              textured_light {
  2681.                 color fexper
  2682.                 [scale/translate/rotate/shear]
  2683.                 }
  2684.  
  2685.           Sample file: environ.pi, ilight.pi
  2686.  
  2687.           2.4.2 Background color
  2688.  
  2689.           The background color is the one used if the current ray does not
  2690.           strike any objects.  The color can be any vector expression,
  2691.           although is usually a simple RGB color value.
  2692.  
  2693.           The format of the declaration is:
  2694.  
  2695.               background <R,G,B>
  2696.            or
  2697.               background color
  2698.  
  2699.           If no background color is set black will be used.
  2700.  
  2701.           An interesting trick that can be performed with the background is
  2702.           to use an image map as the background color (it is also a way to
  2703.           translate from one Targa format to another).  The way this can be
  2704.           done is:
  2705.  
  2706.           background planar_imagemap(image("test1.tga", P)
  2707.  
  2708.           Note that there are problems associated with textured backgrounds
  2709.           - if you have reflectivity in the scene & a reflected ray doesn't
  2710.           hit an object, it may reflect an undesired part of the
  2711.           "background".
  2712.  
  2713.                                                                              50
  2714.  
  2715.  
  2716.  
  2717.           2.4.3 Textures
  2718.  
  2719.           Polyray supports a few simple procedural textures: a standard
  2720.           shading model, a checker texture, a hexagon texture, a noise
  2721.           texture, and layered textures.  In addition, a very flexible
  2722.           (although slower) functional texture is supported.  The general
  2723.           syntax of a texture is:
  2724.  
  2725.              texture { [texture declaration] }
  2726.           or
  2727.              texture_sym
  2728.  
  2729.           Where "texture_sym" is a previously defined texture declaration.
  2730.  
  2731.           2.4.3.1 Procedural Textures
  2732.  
  2733.           2.4.3.1.1 Standard Shading Model
  2734.  
  2735.           Unlike many other ray-tracers, surfaces in Polyray do not have a
  2736.           single color that is used for all of the components of the
  2737.           shading model.  Instead a number of characteristics of the
  2738.           surface must be defined (with a matte white being the default).
  2739.  
  2740.           A surface declaration has the form:
  2741.  
  2742.                surface {
  2743.                   [ surface definitions ]
  2744.                   }
  2745.  
  2746.           For example, the following declaration is a red surface with a
  2747.           white highlight, corresponding to the often seen "plastic"
  2748.           texture:
  2749.  
  2750.              define shiny_red
  2751.              texture {
  2752.                 surface {
  2753.                    ambient red, 0.2
  2754.                    diffuse red, 0.6
  2755.                    specular white, 0.8
  2756.                    microfacet Reitz 10
  2757.                    }
  2758.                 }
  2759.  
  2760.           The allowed surface characteristics that can be defined are:
  2761.  
  2762.              ambient              - Light given off by the surface
  2763.              diffuse              - Light reflected in all directions
  2764.              specular             - Amount and color of specular highlights
  2765.              reflection           - Reflectivity of the surface
  2766.  
  2767.                                                                              51
  2768.  
  2769.  
  2770.              transmission         - Amount and color of refracted light
  2771.              microfacet           - Specular lighting model (see below)
  2772.  
  2773.           The lighting equation used is (in somewhat simplified terms):
  2774.  
  2775.              L = ambient + diffuse + specular + reflected + transmitted, or
  2776.  
  2777.              L = Ka + Kd * (l1 + l2 + ...) + Ks * (l1 + l2 + ...) + Kr + Kt
  2778.  
  2779.           Where l1, l2, ... are the lights, Ka is the ambient term, Kd is
  2780.           the diffuse term, Ks is the specular term, Kr is the reflective
  2781.           term, and Kt it the transmitted (refractive) term. Each of these
  2782.           terms has a scale value and a filter value (the filter defaults
  2783.           to white/clear if unspecified).
  2784.  
  2785.           See the file "colors.inc" for a number of declarations of surface
  2786.           characteristics, including: mirror, glass, shiny, and matte.
  2787.  
  2788.           For lots of detail on lighting models, and the theory behind how
  2789.           color is used in computer generated images, run (don't walk) down
  2790.           to your local computer bookstore and get:
  2791.  
  2792.                 "Illumination and Color in Computer Generated Imagery"
  2793.                 Roy Hall, 1989
  2794.                 Springer Verlag
  2795.  
  2796.           Source code in the back of that book was the inspiration for the
  2797.           microfacet distribution models implemented for Polyray.
  2798.  
  2799.           Note that you don't really have to specify all of the color
  2800.           components if you don't want to.  If the color of a particular
  2801.           part of the surface declaration is not defined, then the value of
  2802.           the "color" component will be examined to see if it was declared.
  2803.           If so, then that color will be used as the filter.  As an
  2804.           example, the declaration above could also be written as:
  2805.  
  2806.              define shiny_red
  2807.              texture {
  2808.                 surface {
  2809.                    color red
  2810.                    ambient 0.2
  2811.                    diffuse 0.6
  2812.                    specular white, 0.8
  2813.                    microfacet Reitz 10
  2814.                    }
  2815.                 }
  2816.  
  2817.           2.4.3.1.1.1 Ambient light
  2818.  
  2819.           Ambient lighting is the light given off by the surface itself.
  2820.  
  2821.                                                                              52
  2822.  
  2823.  
  2824.  
  2825.           The format of the declaration is:
  2826.  
  2827.               ambient color, scale
  2828.               ambient scale
  2829.  
  2830.           As always, color indicates either an RGB triple like
  2831.           <1.0,0.7,0.9>, or a named color.  scale gives the amount of
  2832.           contribution that ambient gives to the overall amount light
  2833.           coming from the pixel.  The scale values should lie in the range
  2834.           0.0 -> 1.0
  2835.  
  2836.           2.4.3.1.1.2 Diffuse light
  2837.  
  2838.           Diffuse lighting is the light given off by the surface under
  2839.           stimulation by a light source.
  2840.  
  2841.           The format of the declaration is:
  2842.  
  2843.               diffuse color, scale
  2844.               diffuse scale
  2845.  
  2846.           The only information used for diffuse calculations is the angle
  2847.           of incidence of the light on the surface.
  2848.  
  2849.           2.4.3.1.1.3 Specular highlights
  2850.  
  2851.           The format of the declaration is:
  2852.  
  2853.              specular color, scale
  2854.              specular scale
  2855.  
  2856.           The means of calculating specular highlights is by default the
  2857.           Phong model.  Other models are selected through the Microfacet
  2858.           distribution declaration.
  2859.  
  2860.           2.4.3.1.1.4 Reflected light
  2861.  
  2862.           Reflected light is the color of whatever lies in the reflected
  2863.           direction as calculated by the relationship of the view angle and
  2864.           the normal to the surface.
  2865.  
  2866.           The format of the declaration is:
  2867.  
  2868.              reflection scale
  2869.              reflection color, scale
  2870.  
  2871.           Typically, only the scale factor is included in the reflection
  2872.           declaration, this corresponds to all colors being reflected with
  2873.           intensity proportional to the scale.  A color filter is allowed
  2874.  
  2875.                                                                              53
  2876.  
  2877.  
  2878.           in the reflection definition, and this allows the modification of
  2879.           the color being reflected (I'm not sure if this is useful, but I
  2880.           included it anyway).
  2881.  
  2882.           2.4.3.1.1.5 Transmitted light
  2883.  
  2884.           Transmitted light is the color of whatever lies in the refracted
  2885.           direction as calculated by the relationship of the view angle,
  2886.           the normal to the surface, and the index of refraction of the
  2887.           material.
  2888.  
  2889.           The format of the declaration is:
  2890.  
  2891.              transmit scale, ior
  2892.              transmit color, scale, ior
  2893.  
  2894.           Typically, only the scale factor is included in the transmitted
  2895.           declaration, this corresponds to all colors being transmitted
  2896.           with intensity proportional to the scale.  A color filter is
  2897.           allowed in the transmitted definition, and this allows the
  2898.           modification of the color being transmitted by making the
  2899.           transmission filter different from the color of the surface
  2900.           itself.
  2901.  
  2902.           It is possible to have surfaces with colors very different than
  2903.           the one closest to the eye become apparent.  (See "gsphere.pi"
  2904.           for an example, a red sphere is in the foreground, a green sphere
  2905.           and a blue sphere behind.  The specular highlights of the red
  2906.           sphere go to yellow, and blue light is transmitted through the
  2907.           red sphere.)
  2908.  
  2909.           A more complex file is "lens.pi" in which two convex lenses are
  2910.           lined up in front of the viewer.  The magnified view of part of a
  2911.           grid of colored balls is very apparent in the front lens.
  2912.  
  2913.           2.4.3.1.1.6 Microfacet distribution
  2914.  
  2915.           The microfacet distribution is a function that determines how the
  2916.           specular highlighting is calculated for an object.
  2917.  
  2918.           The format of the declaration is:
  2919.  
  2920.              microfacet Distribution_name falloff_angle
  2921.              microfacet falloff_angle
  2922.  
  2923.           The distribution name is one of: Blinn, Cook, Gaussian, Phong,
  2924.           Reitz.  The falloff angle is the angle at which the specular
  2925.           highlight falls to 50% of its maximum intensity.  (The smaller
  2926.           the falloff angle, the sharper the highlight.)  If a microfacet
  2927.           name is not given, then the Phong model is
  2928.  
  2929.                                                                              54
  2930.  
  2931.  
  2932.           used.
  2933.  
  2934.           The falloff angle must be specified in degrees, with values in
  2935.           the range
  2936.           0 to 45.  The falloff angle corresponds to the roughness of the
  2937.           surface, the smaller the angle, the smoother the surface.  A very
  2938.           wide falloff angle will give the same sort of shading that
  2939.           diffuse shading gives.
  2940.  
  2941.           Note: as stated before, look at the book by Hall.  I have found
  2942.           falloff values of 5-10 degrees to give nice tight highlights.
  2943.           Using falloff angle may seem a bit backwards from other
  2944.           raytracers, which typically use a value defining the power of a
  2945.           cosine function to define highlight size.  When using a power
  2946.           value, the higher the power, the smaller the highlight.  Using
  2947.           angles seems a little tidier since the smaller the angle, the
  2948.           smaller the highlight.
  2949.  
  2950.           2.4.3.1.2 Checker
  2951.  
  2952.           the checker texture has the form:
  2953.  
  2954.              texture {
  2955.                 checker texture1, texture2
  2956.                 }
  2957.  
  2958.           where texture1 and texture2 are texture declarations (or texture
  2959.           constants).
  2960.  
  2961.           A standard sort of checkered plane can be defined with the
  2962.           following:
  2963.  
  2964.              // Define a matte red surface
  2965.              define matte_red
  2966.              texture {
  2967.                 surface {
  2968.                    ambient red, 0.1
  2969.                    diffuse red, 0.5
  2970.                    }
  2971.                 }
  2972.  
  2973.              // Define a matte blue surface
  2974.              define matte_blue
  2975.              texture {
  2976.                 surface {
  2977.                    ambient blue, 0.2
  2978.                    diffuse blue, 0.8
  2979.                    }
  2980.                 }
  2981.  
  2982.  
  2983.                                                                              55
  2984.  
  2985.  
  2986.              // Define a plane that has red and blue checkers
  2987.              object {
  2988.                 disc <0, 0.01, 0>, <0, 1, 0>, 5000
  2989.                 texture {
  2990.                    checker matte_red, matte_blue
  2991.                    }
  2992.                 }
  2993.  
  2994.           For a sample file, look at "spot0.pi".  This file has a sphere
  2995.           with a red/blue checker, and a plane with a black/white checker.
  2996.  
  2997.           Note A distinct problem with checkerboards is one of aliasing at
  2998.           great distances.  To help with aliasing, either use larger checks
  2999.           (by adding a scale to the texture), or make sure there is a very
  3000.           low light level at great distances.
  3001.  
  3002.           2.4.3.1.3 Hexagon
  3003.  
  3004.           the hexagon texture is oriented in the x-z plane, and has the
  3005.           form:
  3006.  
  3007.              texture {
  3008.                 hexagon texture1, texture2, texture3
  3009.                 }
  3010.  
  3011.           This texture produces a honeycomb tiling of the three textures in
  3012.           the declaration.  Remember that this tiling is with respect to
  3013.           the x-z plane, if you want it on a vertical wall you will need to
  3014.           rotate the texture.
  3015.  
  3016.           2.4.3.1.4 Noise surfaces
  3017.  
  3018.           The complexity and speed of rendering of the noise surface type
  3019.           lies between the standard shading model and the special surfaces
  3020.           described below.  It is an attempt to capture a large number of
  3021.           the standard 3D texturing operations in a single declaration.
  3022.  
  3023.           A noise surface declaration has the form:
  3024.  
  3025.                texture {
  3026.                   noise surface {
  3027.                      [ noise surface definition ]
  3028.                      }
  3029.                   }
  3030.  
  3031.           The allowed surface characteristics that can be defined are:
  3032.  
  3033.             color <r, g, b>         Basic surface color (used if the noise
  3034.                                     function generates a value not
  3035.                                     contained in the color map)
  3036.  
  3037.                                                                              56
  3038.  
  3039.  
  3040.  
  3041.             ambient scale           Amount of ambient contribution
  3042.  
  3043.             diffuse scale           Diffuse contribution
  3044.  
  3045.             specular color, scale   Amount and color of specular
  3046.                                     highlights, if the color is not given
  3047.                                     then the body color is used.
  3048.  
  3049.             reflection scale        Reflectivity of the surface
  3050.  
  3051.             transmission scale, ior Amount of refracted light
  3052.  
  3053.             microfacet kind angle   Specular lighting model (see the
  3054.                                     description of a standard surface)
  3055.  
  3056.  
  3057.  
  3058.             color_map(map_entries)  Define the color map (see
  3059.                                     following section on color map
  3060.                                     definitions for further details)
  3061.  
  3062.             bump_scale fexper       How much the bumpiness affects the
  3063.                                     normal to the surface
  3064.  
  3065.             frequency fexper        Affects the wavelength of ripples and
  3066.                                     waves
  3067.  
  3068.             phase fexper            Affects the phase of the ripples and
  3069.                                     waves
  3070.  
  3071.             lookup_fn index         Selects a predefined lookup function
  3072.  
  3073.             normal_fn index         Selects a predefined normal modifier
  3074.  
  3075.             octaves fexper          Number of octaves of noise to use
  3076.  
  3077.             position_fn index       How the intersection point is used in
  3078.                                     the process of generating a noise
  3079.                                     texture
  3080.  
  3081.             position_scale fexper   Amount of contribution of the position
  3082.                                     value to the overall texture
  3083.  
  3084.             turbulence fexper       Amount of contribution of the noise to
  3085.                                     the overall texture.
  3086.  
  3087.  
  3088.           The way the final color of the texture is decided is by
  3089.           calculating a floating point value using the following general
  3090.  
  3091.                                                                              57
  3092.  
  3093.  
  3094.           formula:
  3095.  
  3096.              index = lookup_fn(position_scale * position_fn +
  3097.                                turbulence * noise3d(P, octaves))
  3098.  
  3099.           The index value that is calculated is then used to lookup a color
  3100.           from the color map.  This final color is used for the ambient,
  3101.           diffuse, reflection and transmission filters.  The functions that
  3102.           are currently available, with their corresponding indices are:
  3103.  
  3104.           Position functions:
  3105.              Index       Effect
  3106.                  1        x value in the object coordinate system
  3107.                  2        x value in the world coordinate system
  3108.                  3        Distance from the z axis
  3109.                  4        Distance from the origin
  3110.                  5        Distance around the y-axis (ranges from 0 -> 1)
  3111.               default:    0.0
  3112.  
  3113.           Lookup functions:
  3114.              Index       Effect
  3115.                  1        sawtooth function, result from 0 -> 1
  3116.                  2        sin function, result from 0->1
  3117.                  3        ramp function, result from 0->1
  3118.               default:    no modification made
  3119.  
  3120.           Definitions of these function numbers that make sense are:
  3121.  
  3122.           define position_plain       0
  3123.           define position_objectx     1
  3124.           define position_worldx      2
  3125.           define position_cylindrical 3
  3126.           define position_spherical   4
  3127.           define position_radial      5
  3128.  
  3129.           define lookup_plain    0
  3130.           define lookup_sawtooth 1
  3131.           define lookup_sin      2
  3132.           define lookup_ramp     3
  3133.  
  3134.           An example of a texture defined this way is a simple white
  3135.           marble:
  3136.  
  3137.              define white_marble_texture
  3138.              texture {
  3139.                 noise surface {
  3140.                    color white
  3141.                    position_fn position_objectx
  3142.                    lookup_fn lookup_sawtooth
  3143.                    octaves 3
  3144.  
  3145.                                                                              58
  3146.  
  3147.  
  3148.                    turbulence 3
  3149.                    ambient 0.2
  3150.                    diffuse 0.8
  3151.                    specular 0.3
  3152.                    microfacet Reitz 5
  3153.                    color_map(
  3154.                       [0.0, 0.8, <1, 1, 1>, <0.6, 0.6, 0.6>]
  3155.                       [0.8, 1.0, <0.6, 0.6, 0.6>, <0.1, 0.1, 0.1>])
  3156.                    }
  3157.                 }
  3158.  
  3159.           In addition to coloration, the bumpiness of the surface can be
  3160.           affected by selecting a function to modify the normal.  The
  3161.           currently supported normal modifier functions are:
  3162.  
  3163.              Index       Effect
  3164.                  1        Make random bumps in the surface
  3165.                  2        Add ripples to the surface
  3166.                  3        Give the surface a dented appearance
  3167.               default:    no change
  3168.  
  3169.           Definitions that make sense are:
  3170.  
  3171.           define default_normal 0
  3172.           define bump_normal    1
  3173.           define ripple_normal  2
  3174.           define dented_normal  3
  3175.  
  3176.           See also the file "texture.txt" for a little more explanation and
  3177.           a few more texture definitions.
  3178.  
  3179.           Sample file: textures.inc
  3180.  
  3181.           2.4.3.1.5 Layered Textures
  3182.  
  3183.           A layered texture is a way of piling one texture on top of
  3184.           another.  If the top most texture has any transparency, the layer
  3185.           below it will be shaded, and its color will be added to the color
  3186.           generated in the first layer.  This process repeats through every
  3187.           layer until either an opaque layer is reached, or there are no
  3188.           more layers.
  3189.  
  3190.           The format of the declaration is:
  3191.  
  3192.              texture {
  3193.                 layered
  3194.                    texture1,
  3195.                    texture2,
  3196.                    ...
  3197.                    textureN
  3198.  
  3199.                                                                              59
  3200.  
  3201.  
  3202.                 }
  3203.  
  3204.           The first texture in the list is the top texture layer, the last
  3205.           is the bottom texture layer.  As an example, the following
  3206.           defines a marble texture that has mirror in its veins.  The way
  3207.           it works is by using an alpha value in the color map, so as the
  3208.           color in the vein goes to black, the alpha increases to 1.0.  The
  3209.           bottom layer in this case is mirror, and only appears when we are
  3210.           looking into the veined part of the texture.
  3211.  
  3212.  
  3213.              // Sample Polyray file
  3214.              // A gradient texture with changing 'alpha' values
  3215.              //
  3216.              viewpoint {
  3217.                 from <0, 2, -10>
  3218.                 at <0,0,0>
  3219.                 up <0,1,0>
  3220.                 angle 35
  3221.                 resolution 80, 80
  3222.                 aspect 1
  3223.                 }
  3224.  
  3225.              include "colors.inc"
  3226.  
  3227.              background midnightblue
  3228.              light <-10, 7, -5>
  3229.  
  3230.              define position_objectx 1
  3231.              define lookup_sawtooth  1
  3232.  
  3233.              // Make a variant on white marble that has transparency in its
  3234.              // veins
  3235.              define alpha_white_marble
  3236.              texture {
  3237.                 noise surface {
  3238.                    color white
  3239.                    position_fn position_objectx
  3240.                    lookup_fn lookup_sawtooth
  3241.                    octaves 3
  3242.                    turbulence 3
  3243.                    ambient 0.3
  3244.                    diffuse 0.8
  3245.                    specular 0.3
  3246.                    microfacet Reitz 5
  3247.                    color_map([0.0, 0.2, white, 0,   white, 0]
  3248.                              [0.2, 0.5, white, 0,   black, 0.2]
  3249.                              [0.6, 1.0, black, 0.2, black, 1])
  3250.                    }
  3251.                 }
  3252.  
  3253.                                                                              60
  3254.  
  3255.  
  3256.  
  3257.              // We now build the layered texture from the one just
  3258.              // defined, as well as the "mirror" texture from "colors.inc"
  3259.              define mirror_veined_marble
  3260.              texture {
  3261.                 layered
  3262.                    alpha_white_marble,
  3263.                    mirror
  3264.                 }
  3265.  
  3266.              // Make a sphere that has the layered texture
  3267.              object {
  3268.                 sphere <0, 0, 0>, 2
  3269.                 mirror_veined_marble
  3270.                 }
  3271.  
  3272.              // Add a checkered floor, so we see something in the mirrored
  3273.              // part of the sphere.
  3274.              object {
  3275.                 disc <0, -2.005, 0>, <0, 1, 0>, 10
  3276.                 texture { checker matte_white, matte_black }
  3277.                 }
  3278.  
  3279.           Sample files: layer1.pi, layer2.pi
  3280.  
  3281.           2.4.3.2 Functional Textures
  3282.  
  3283.           The most general textures in Polyray are functional textures.
  3284.           These textures are evaluated at run-time based on the expressions
  3285.           given for the components of the lighting model.  The general
  3286.           syntax for a surface using a functional texture is:
  3287.  
  3288.              special surface {
  3289.                 [ surface declaration ]
  3290.                 }
  3291.  
  3292.           In addition to the components usually defined in a surface
  3293.           declaration, it is possible to define a function that deflects
  3294.           the normal, and a "body" color that will be used as the color
  3295.           filter in the ambient, diffuse, etc. components of the surface
  3296.           declaration.  The format of the two declarations
  3297.           are:
  3298.  
  3299.              color vexper
  3300.           and
  3301.              normal vexper
  3302.  
  3303.           An example of how a functional texture can be defined is:
  3304.  
  3305.              define sin_color_offset (sin(3.14*fmod(x*y*z,1)+otheta)+1)/2
  3306.  
  3307.                                                                              61
  3308.  
  3309.  
  3310.              define sin_color <sin_color_offset, 0, 1 - sin_color_offset>
  3311.  
  3312.              define xyz_sin_texture
  3313.              texture {
  3314.                 special surface {
  3315.                    color sin_color
  3316.                    ambient 0.2
  3317.                    diffuse 0.7
  3318.                    specular white, 0.2
  3319.                    microfacet Reitz 10
  3320.                    }
  3321.                 }
  3322.  
  3323.           In this example, the color of the surface is defined based on the
  3324.           location of the intersection point using the vector defined as
  3325.           "sin_color".
  3326.  
  3327.           Sample files: cossph.pi, cwheel.pi.
  3328.  
  3329.           2.4.3.2.1 Image maps
  3330.  
  3331.           A type of coloring that can be used involves the use of an
  3332.           existing image projected onto a surface.  There are four types of
  3333.           projection supported, planar, cylindrical, spherical, and
  3334.           environment.  Input files for use as image maps may be 8, 16, 24,
  3335.           and 32 bit uncompressed, RLE compressed, or color mapped Targa
  3336.           files.
  3337.  
  3338.           The declaration of an image map is:
  3339.  
  3340.              image("imfile.tga")
  3341.  
  3342.           Typically, an image will be associated with a variable through a
  3343.           definition such as:
  3344.  
  3345.              define myimage image("imfile.tga")
  3346.  
  3347.           The image is projected onto a shape by means of a "projection".
  3348.           The four types of projection are declared by:
  3349.  
  3350.              planar_imagemap(image, coordinate [, repeat]),
  3351.              cylindrical_imagemap(image, coordinate [, repeat]),
  3352.              spherical_imagemap(image, coordinate)
  3353.              environment_map(environment(image1, image2, image3, image4,
  3354.                                          image5, image6))
  3355.  
  3356.           The planar projection maps the entire raster image into the
  3357.           coordinates 0 <= x <= 1, 0 <= z <= 1.  The vector value given as
  3358.           "coordinate" is used to select a color by multiplying the x value
  3359.           by the number of columns, and the z value by the number of rows.
  3360.  
  3361.                                                                              62
  3362.  
  3363.  
  3364.           The color appearing at that position in the raster will then be
  3365.           returned as the result.  If a "repeat" value is given then entire
  3366.           surface, repeating between every integer Value of x and/or z.
  3367.  
  3368.           The cylindrical projection wraps the image about a cylinder that
  3369.           has one end at the origin and the other at <0, 1, 0>.  If a
  3370.           "repeat" value is given, then the image will be repeated along
  3371.           the y-axis, if none is given, then any part of the object that is
  3372.           not covered by the image will be given the color of pixel (0, 0).
  3373.  
  3374.           The spherical projection wraps the image about an origin centered
  3375.           sphere.  The top and bottom seam are folded into the north and
  3376.           south poles respectively.  The left and right edges are brought
  3377.           together on the positive x axis.
  3378.  
  3379.           The environment map wraps six images around a point.  This method
  3380.           is a standard way to fake reflections by wrapping the images that
  3381.           would be seen from a point inside an object around the object.  A
  3382.           sample of this technique can be seen by rendering "room1.pi"
  3383.           (which generates the images) followed by rendering "room0.pi"
  3384.           (which wraps the images around a sphere).
  3385.  
  3386.           Following are a couple of examples of objects and textures that
  3387.           make use of image maps:
  3388.  
  3389.              define hivolt_image image("hivolt.tga")
  3390.              define hivolt_tex
  3391.              texture {
  3392.                 special surface {
  3393.                    color cylindrical_imagemap(hivolt_image, P, 1)
  3394.                    ambient 0.9
  3395.                    diffuse 0.1
  3396.                    }
  3397.                 scale <1, 2, 1>
  3398.                 translate <0, -1, 0>
  3399.                 }
  3400.              object { cylinder <0, -1, 0>, <0, 1, 0>, 3 hivolt_tex }
  3401.  
  3402.           and
  3403.  
  3404.              define disc_image image("test.tga")
  3405.              define disc_tex
  3406.              texture {
  3407.                 special surface {
  3408.                    color planar_imagemap(disc_image, P)
  3409.                    ambient 0.9
  3410.                    diffuse 0.1
  3411.                    }
  3412.                 translate <-0.5, 0, -0.5>
  3413.                 scale <7*4/3, 1, 7>
  3414.  
  3415.                                                                              63
  3416.  
  3417.  
  3418.                 rotate <90, 0, 0>
  3419.                 }
  3420.              object {
  3421.                 disc <0, 0, 0>, <0, 0, 1>, 6
  3422.                 u_steps 10
  3423.                 disc_tex
  3424.                 }
  3425.  
  3426.           2.5 Comments
  3427.  
  3428.           Single line comments are allowed and have the following format:
  3429.  
  3430.              // [ any text to end of the line ]
  3431.  
  3432.           As soon as the two characters "//" are detected, the rest of the
  3433.           line is considered a comment.
  3434.  
  3435.           2.6 Animation support
  3436.  
  3437.           An animation is generated by rendering a series of frames,
  3438.           numbered from 0 to some total value.  The declarations in polyray
  3439.           that support the generation of multiple Targa images are:
  3440.  
  3441.             total_frames val  The total number of frames in the animation
  3442.  
  3443.             start_frame val   The value of the first frame to be rendered
  3444.  
  3445.             end_frame val     The last frame to be rendered
  3446.  
  3447.             outfile "name"
  3448.             outfile name      Polyray appends the frame number to this
  3449.                               string in order to generate distinct Targa
  3450.                               files.
  3451.  
  3452.  
  3453.           The values of "total_frames", "start_frame", and "end_frame", as
  3454.           well as the value of the current frame, "frame", are usable in
  3455.           arithmetic expressions in the input file.  Note that these
  3456.           statements should appear before the use of: total_frames,
  3457.           start_frame, end_frame, or frame as a part of an expression.
  3458.           Typically I put the declarations right at the top of the file.
  3459.  
  3460.           WARNING: if the string given for "outfile" is longer than 5
  3461.           characters, the three digit frame number that is appended will be
  3462.           truncated by DOS.  Make sure this string is short enough or you
  3463.           will end up overwriting image files.
  3464.  
  3465.           Sample files: whirl.pi, plane.pi, squish.pi
  3466.  
  3467.           2.7 Conditional processing
  3468.  
  3469.                                                                              64
  3470.  
  3471.  
  3472.  
  3473.           In support of animation generation (and also because I sometimes
  3474.           like to toggle attributes of objects), polyray supports limited
  3475.           conditional processing.  The syntax for this is:
  3476.  
  3477.              if (cexper) {
  3478.                 [object/light/... declarations]
  3479.                 }
  3480.              else {
  3481.                 [other object/light/... declarations]
  3482.                 }
  3483.  
  3484.           The sample file "rsphere.pi" shows how it can be used to modify
  3485.           the color characteristics of a moving sphere.
  3486.  
  3487.           The use of conditional statements is limited to the top level of
  3488.           the data file.  You cannot put a conditional within an object or
  3489.           texture declaration. i.e.
  3490.  
  3491.              object {
  3492.                 if (foo == 42) {
  3493.                    sphere <0, 0, 0>, 4
  3494.                    }
  3495.                 else {
  3496.                    disc <0, 0, 0>, <0, 1, 0>, 4
  3497.                    }
  3498.                 }
  3499.  
  3500.           is not a valid use of an "if" statement, whereas:
  3501.  
  3502.              if (foo == 42) {
  3503.                 object {
  3504.                    sphere <0, 0, 0>, 4
  3505.                    }
  3506.                 }
  3507.              else {
  3508.                 object {
  3509.                    disc <0, 0, 0>, <0, 1, 0>, 4
  3510.                    }
  3511.                 }
  3512.           or
  3513.              if (foo == 42)
  3514.                 object { sphere <0, 0, 0>, 4 }
  3515.              else if (foo = 12) {
  3516.                 object { torus 3.0, 1.0, <0, 0, 0>, <0, 1, 0> }
  3517.                 object { cylinder <0, -1, 0>, <0, 1, 0>, 0.5 }
  3518.                 }
  3519.              else
  3520.                 object { disc <0, 0, 0>, <0, 1, 0>, 4 }
  3521.  
  3522.  
  3523.                                                                              65
  3524.  
  3525.  
  3526.           are valid.
  3527.  
  3528.           Note: the curly brackets "{}" are required if there are multiple
  3529.           statements within the conditional, and not required if there is a
  3530.           single statement.
  3531.  
  3532.           2.8 Include files
  3533.  
  3534.           In order to allow breaking an input file into several files (as
  3535.           well as supporting the use of library files), it is possible to
  3536.           direct polyray to process another file.  The syntax is:
  3537.  
  3538.              include "filename"
  3539.  
  3540.           Beware that trying to use "#include ..." will fail as Polyray
  3541.           will consider it a comment.
  3542.  
  3543.           2.9 File flush
  3544.  
  3545.           Due to unforeseen occurrences, like power outages, or roommates
  3546.           that hit the reset button so they can do word processing, it is
  3547.           possible to specify how often the output file will be flushed to
  3548.           disk.  The default is to wait until the entire file has been
  3549.           written before a flush (which is a little quicker but you lose
  3550.           everything if a crash occurs).
  3551.  
  3552.           The format of the declaration is:
  3553.  
  3554.              file_flush xxx
  3555.  
  3556.           The number xxx indicates the maximum number of pixels that will
  3557.           be written before a file flush will occur.  This value can be as
  3558.           low as 1 - this will force a flush after every pixel (only for
  3559.           the very paranoid).
  3560.  
  3561.           3 File formats
  3562.  
  3563.           3.1 Output files
  3564.  
  3565.           Currently the output file formats are 8, 16, 24, and 32 bit
  3566.           uncompressed and RLE compressed Targa (types 2, 3, and 10).  If
  3567.           no output file is defined with the '-o' command line option, the
  3568.           file "out.tga" will be used.  The command line option -u
  3569.           specifies that no compression should be used on the output file.
  3570.  
  3571.           The default output format is an RLE compressed 16 bit color
  3572.           format.  This format holds 5 bits for each of red, green, and
  3573.           blue.  The reason for choosing this format is that very few can
  3574.           afford 24 bit color boards and this format meets the limits of
  3575.           the typical 8 and 15 bit color boards.  If you have the hardware
  3576.  
  3577.                                                                              66
  3578.  
  3579.  
  3580.           to display more than 32K colors then set the command line
  3581.           switches or set the defaults in the initialization file to
  3582.           generate 24 or 32 bit Targa files.  If you are only interested in
  3583.           greyscale images, the 8 bit format is appropriate.
  3584.  
  3585.           4 Algorithms
  3586.  
  3587.           4.1 Processing polynomial expressions
  3588.  
  3589.           The program in its current form allows the definition of
  3590.           polynomial surfaces of degree less than 33 (Due to numerical
  3591.           problems, don't bother with polynomials of degree more than
  3592.           around 10, and if possible keep them less than 6.)
  3593.  
  3594.           The way that polynomial expressions are processed and manipulated
  3595.           follows the following steps:
  3596.  
  3597.                1) Parse the expression as taken from the input file.  The
  3598.                   YACC parser that is used to process the input file
  3599.                   creates a parse tree of the expression as it is read.
  3600.                   The format for allowed expressions is described in
  3601.                   section 4.1.2.
  3602.  
  3603.                2) Expand the expression into a sum of simple
  3604.                   subexpressions.  After the parse tree has been built,
  3605.                   the expression is expanded so that the expression is in
  3606.                   expanded form. (i.e. (x+1)^2 is rewritten as x^2 + 2*x +
  3607.                   1.)  The rules for doing this are explained in section
  3608.                   4.1.3.
  3609.  
  3610.                3) Determine what order polynomial is represented by the
  3611.                   expression.  Every term in the expanded expression is
  3612.                   examined to see what the largest order of x, y, and z is
  3613.                   used.  This determines the order N of the polynomial.
  3614.                   From this value, the number of possible terms of that
  3615.                   order is computed.
  3616.  
  3617.                4) Create an array of coefficients for the general three
  3618.                   variable polynomial equation of order N.  There are a
  3619.                   total of (N+1)*(N+2)*(N+3)/6 terms in the general
  3620.                   equation.  The values of each of the coefficients in the
  3621.                   expanded expression are then substituted into the array
  3622.                   of coefficients.
  3623.  
  3624.  
  3625.           Note that the storage of expressions is not particularly
  3626.           efficient for high orders of N.
  3627.  
  3628.           4.1.1 Example equation representation
  3629.  
  3630.  
  3631.                                                                              67
  3632.  
  3633.  
  3634.           As an example of how the parse tree is expanded, given the input:
  3635.  
  3636.              (x+y)*(1-x-z) + (x-z)^2.
  3637.  
  3638.           The expanded representation is:
  3639.  
  3640.              -1*x*y + -3*x*z + x + -1*y*z + y + z^2
  3641.  
  3642.           This is a polynomial of order 2, and the array of coefficients
  3643.           is:
  3644.  
  3645.              0 0 1 -1 -3 -1 1 1 0 0
  3646.  
  3647.           4.1.2 Allowed Formula Syntax
  3648.  
  3649.           The keyword here is "simple" algebraic expressions.  The only
  3650.           allowed variables are "x", "y", and "z" (and only lower case).
  3651.           Constants are floating point numbers.  The operations allowed
  3652.           between constants and the three variable symbols are: addition,
  3653.           subtraction, multiplication, unary minus, and exponentiation by
  3654.           an positive integer power.  Examples of expressions that can be
  3655.           processed are:
  3656.  
  3657.                 x^2+y-42
  3658.                 (1+x+y+z)^2 * 2*(x-y)*(z-x*(133-z^2))
  3659.                 27*x-y*42*y^2
  3660.                 (x^2+y^2+z^2+3)^2 - (x*y-x^2)*z^2
  3661.  
  3662.           Examples of expressions that cannot be processed are:
  3663.  
  3664.                 x/y
  3665.                 x^0.5+y
  3666.                 2(x-y)
  3667.                 x^-2
  3668.  
  3669.           4.1.3 Rules for processing formulas
  3670.  
  3671.           There are only a few rules needed to simplify a polynomial
  3672.           expression to the point that it can be easily turned into an
  3673.           array of coefficients. They appear below, with the letters A, B,
  3674.           C, and D standing for an arbitrary sub-expression.  The rules
  3675.           used to simplify an expression are:
  3676.  
  3677.              Addition:
  3678.                 No simplification needed for the term: A + B
  3679.  
  3680.              Subtraction:
  3681.                 A-B          ->      A + (-B)
  3682.  
  3683.              Unary minus:
  3684.  
  3685.                                                                              68
  3686.  
  3687.  
  3688.                 -(A*B)       ->      (-A * B)
  3689.                 -(A+B)       ->      (-A + -B)
  3690.  
  3691.              Multiplication:
  3692.                 A*(B+C)      ->      A*B + A*C
  3693.                 (A+B)*C      ->      A*C + B*C
  3694.                 (A+B)*(C+D)  ->      A*C + A*D + B*C + B*D
  3695.  
  3696.              Exponentiation:
  3697.                 (A*B)^n      ->      A^n * B^n
  3698.                 (A+B)^n      ->      C(n,0) * A^n + C(n,1) * A^(n-1) * B + ...
  3699.                                        C(n,n-1) * A * B^(n-1) + C(n,n) * B^n
  3700.                                     { C(n, r) is the binomial coefficient }
  3701.  
  3702.           Each of the subexpressions is further simplified until every term
  3703.           in the expression has the form: const * x^i * y^j * z^k.
  3704.  
  3705.           4.2 Processing of arbitrary functional surfaces
  3706.  
  3707.           The basic algorithm for determining a point of intersection using
  3708.           interval math is quite simple:
  3709.  
  3710.                1) Given a range of allowed values for the ray parameter T,
  3711.                   a range of function values is calculated.
  3712.  
  3713.                2) If the range does not include 0 then there is no
  3714.                   intersection.
  3715.  
  3716.                3) If the range includes 0, then:
  3717.  
  3718.                  A) The range of values of the derivative of the function
  3719.                   is calculated for the allowed values of the ray
  3720.                   parameter T.
  3721.  
  3722.                  B) If the range of values of the derivative includes 0,
  3723.                   then the interval for T is bisected and we process each
  3724.                   subinterval starting with step 1.
  3725.  
  3726.                  C) If the range of values of the derivative does not
  3727.                   include 0, then we know that there is exactly one
  3728.                   solution of the function in the current interval.  A
  3729.                   standard root solver using the regula-falsi method is
  3730.                   called to find the root.
  3731.  
  3732.           There is of course much more to this...
  3733.  
  3734.           4.2.1 Spherical coordinates
  3735.  
  3736.           To ray-trace functions that are defined in terms of spherical
  3737.           coordinates use the substitutions:
  3738.  
  3739.                                                                              69
  3740.  
  3741.  
  3742.  
  3743.              r     = sqrt(x^2 + y^2 + z^2),
  3744.              theta = atan(y/x),
  3745.              phi   = atan(sqrt(x^2 + y^2)/z)
  3746.  
  3747.           Sample file: sectorl.pi, zonal.pi
  3748.  
  3749.           4.3 Three dimensional noise generation
  3750.  
  3751.           The way Polyray generates noise values from vector inputs follows
  3752.           the following steps:
  3753.  
  3754.                1) The integer part of the x, y, and z values of the vector
  3755.                   are determined.
  3756.  
  3757.                2) The eight integer points surrounding the input vector are
  3758.                   determined.
  3759.  
  3760.                3) A hashing function (described below) is applied to the
  3761.                   integer points surrounding the input vector, resulting
  3762.                   in eight random numbers.
  3763.  
  3764.                4) A final number is determine by weighting the values
  3765.                   associated with the surrounding points with the distance
  3766.                   from the input vector to those points.
  3767.  
  3768.  
  3769.           The result of this is that each point on an integer lattice has a
  3770.           random value, but each fractional value inside a unit cube in the
  3771.           lattice is related to its surrounding points.
  3772.  
  3773.           The hashing function I use takes the bottom 10 bits of the
  3774.           integer parts of the input vector, squishes them into a single
  3775.           number, then crunches this value through a series of adds,
  3776.           multiplies, and mods to get a single result.  The algorithm is:
  3777.  
  3778.              K = ((x & 0x03ff) << 20) |
  3779.                  ((y & 0x03ff) << 10) |
  3780.                   (z & 0x03ff);
  3781.              Kt = 0;
  3782.              for (i=0;i<mult_table_size;i++)
  3783.                 Kt = ((Kt + K) * mult_table[i]) % HASH_SIZE;
  3784.              result = (Flt)Kt / (Flt)(HASH_SIZE - 1);
  3785.  
  3786.           The number and value of the entries in "mult_table" were chosen
  3787.           at random, as was the value HASH_SIZE.  I haven't bothered to
  3788.           determine if the results from this hashing function really are
  3789.           spread evenly, however the visual results from using it are quite
  3790.           good.
  3791.  
  3792.  
  3793.                                                                              70
  3794.  
  3795.  
  3796.           4.4 Marching Cubes
  3797.  
  3798.           The marching cubes algorithm puts a lattice over the three
  3799.           dimensional space that an object sits in.  By stepping through
  3800.           each subcube in the lattice and looking for places where the
  3801.           surface passes through a subcube, a good guess at a polygonal
  3802.           cover for the surface can be generated.  This algorithm is used
  3803.           for scan converting blobs, polynomial functions, and implicit
  3804.           functions.
  3805.  
  3806.           As each cube is processed, every vertex of the cube is tested to
  3807.           see if it is inside the object "hot", or outside the object
  3808.           "cold".  There are a total of 2^8 = 256 possible combinations of
  3809.           hot and cold vertices.
  3810.  
  3811.           The processing of each subcube in the lattice takes these steps:
  3812.  
  3813.                o  Each of the 8 vertices of the cube corresponds to a bit
  3814.                   in an unsigned char.  If the vertex is hot then the bit
  3815.                   is set to 1, if the vertex is cold the bit is set to 0.
  3816.  
  3817.                o  Using a little combinatorics and group theory, it is
  3818.                   possible to classify, under the group of solid rotations
  3819.                   of the cube, each of the 256 possibilities to one of 23
  3820.                   unique base cases.  (You can actually drop down to 14,
  3821.                   but it would have made parts of the algorithm more
  3822.                   complicated.)
  3823.  
  3824.                o  Each of the base cases has an entry in a table of
  3825.                   triangles that separate the hot vertices from the cold
  3826.                   vertices for that case.
  3827.  
  3828.                o  By using the inverse of the rotations that took the cube
  3829.                   into the base case, the triangles are rotated to
  3830.                   separate the hot and cold vertices of the original cube.
  3831.  
  3832.                o  The amount of hot and amount of cold that are separated
  3833.                   by each triangle is examined in order to see how much to
  3834.                   push the triangle up or down.  This is a linear
  3835.                   interpolation that helps to keep the triangles close to
  3836.                   the actual surface.
  3837.  
  3838.                o  Now that the triangles are known and in approximately the
  3839.                   right place, the normal scan conversion routine is
  3840.                   called for each triangle.
  3841.  
  3842.  
  3843.           The biggest drawback of this algorithm is that the number of
  3844.           evaluations goes up with the cube of the resolution of the
  3845.           lattice.  For example, if u_steps is 20 and v_steps is 20 (the
  3846.  
  3847.                                                                              71
  3848.  
  3849.  
  3850.           default), then 20x20x20 = 8000 individual subcubes are visited.
  3851.           If you were to increase the resolution by a factor of 5, there
  3852.           would be 100x100x100 = 1,000,000 subcubes visited.
  3853.  
  3854.           Another problem is one of aliasing.  If the surface is very
  3855.           complex and/or contains many small features, and the number of
  3856.           steps along the axes is insufficient to properly determine
  3857.           inside/outside, then large portions of the surface can disappear.
  3858.           The solution is to increase the step sizes, or to raytrace,
  3859.           either option will increase processing time.
  3860.  
  3861.           Note: when I built the table of triangles, I made the assumption
  3862.           that if there are two ways to split hot from cold, that hot would
  3863.           always connect to hot.  One example of this choice is when the
  3864.           vertices: (0, 0, 0), (1, 0, 0), (0, 1, 1), and (1, 1, 1) are all
  3865.           hot and the rest are cold.
  3866.  
  3867.           5 Outstanding Issues
  3868.  
  3869.           Polyray will probably never be "done".  And in this respect, the
  3870.           next two sections list some things that are planned for the
  3871.           future, as well as things that should already have been fixed.
  3872.  
  3873.           5.1 To do list
  3874.  
  3875.                Parameterised objects and textures.  This will occur in the
  3876.                next major release of Polyray, due to the extreme structural
  3877.                changes required.
  3878.  
  3879.                The ability to execute a "system" command.  During the
  3880.                generation of an animation it would be nice to call an
  3881.                external program that in turn generates an include file
  3882.                containing data for the current frame of the animation.
  3883.                (This works in the 286 version & the GCC compiled 386
  3884.                version, but the Zortech compiled 386 version doesn't
  3885.                support system calls.)
  3886.  
  3887.                User definable positioning of display elements, in
  3888.                particular placement of the image as it is drawn, and
  3889.                placement of the status display during the trace.
  3890.  
  3891.                Appending ".pi" to input file names that do not have an
  3892.                extension.
  3893.  
  3894.                Adding a default search path for the init file & include
  3895.                files.
  3896.  
  3897.           5.2 Known Bugs
  3898.  
  3899.                It is possible to specify surface components that have no
  3900.  
  3901.                                                                              72
  3902.  
  3903.  
  3904.                meaning for the type of surface that is being declared. i.e.
  3905.                octaves in a special surface.
  3906.  
  3907.                The initialization file "polyray.ini" has to be in the
  3908.                current directory.
  3909.  
  3910.                Environment maps don't quite mesh at the seams.
  3911.  
  3912.                Shading in scan conversion doesn't always match that from
  3913.                raytracing.  Not much can be done about this other than
  3914.                increasing the values of "u_steps" and "v_steps".
  3915.  
  3916.  
  3917.           6 Revision History
  3918.  
  3919.           Version 1.5
  3920.           Released: 3 November 1992
  3921.  
  3922.                o  Found the missing top line in scan converted images -
  3923.                   Polyray was using the background color for the entire
  3924.                   top line.
  3925.  
  3926.                o  Added layered textures.
  3927.  
  3928.                o  Expression processing code improved - bugs removed,
  3929.                   memory used diminished.
  3930.  
  3931.                o  Plugged memory leaks.  Extensive debugging of memory
  3932.                   allocations and frees performed.  Animations should be
  3933.                   much happier now.
  3934.  
  3935.                o  No longer need to define maximum number of primitives.
  3936.  
  3937.                o  Added support for greyscale Targa (type 3) files.  These
  3938.                   can be used as the output format, as imagemaps, and as
  3939.                   height fields.
  3940.  
  3941.                o  Buggy SVGA support removed.  Only standard VGA mode
  3942.                   (320x200) supported.
  3943.  
  3944.                o  Gridded objects added.
  3945.  
  3946.                o  Arrays added
  3947.  
  3948.                o  Components of CSG objects are now properly sorted by
  3949.                   bounding slabs
  3950.  
  3951.                o  User defined bounding slabs removed.  Polyray will always
  3952.                   use bounding slabs aligned with the x, y, and z-axes.
  3953.  
  3954.  
  3955.                                                                              73
  3956.  
  3957.  
  3958.                o  Clipping and bounding objects removed.  Clipping is now
  3959.                   performed in CSG, bounding is specified using a
  3960.                   "bounding_box" declaration.
  3961.  
  3962.                o  Added wireframe display mode.
  3963.  
  3964.                o  Added planar blob types.  (Also added toroidal blob
  3965.                   types, but they only appear in scan conversion images
  3966.                   due to the extreme numerical precision needed to
  3967.                   raytrace them.)
  3968.  
  3969.                o  Added smooth height fields.
  3970.  
  3971.                o  Fixed shading bug involving transparent objects &
  3972.                   multiple light sources.
  3973.  
  3974.                o  Fixed diffuse lighting from colored lights.
  3975.  
  3976.                o  Changed RLE Targa output so that line boundaries are not
  3977.                   crossed.
  3978.  
  3979.  
  3980.           Version 1.4
  3981.           Released: 11 April 1992
  3982.  
  3983.                o  Support for many SVGA boards at 640x480 resolution in 256
  3984.                   colors.  See documentation for the -V flag. (Note: SVGA
  3985.                   displays only work on the 286 versions.)
  3986.  
  3987.                o  Changed the way the status output is managed.  Now
  3988.                   requires a number following the -t flag.  Note that line
  3989.                   and pixel status will screw up SVGA displays - drawing
  3990.                   goes to the wrong place starting around line 100.  If
  3991.                   using SVGA display then either use no status, or
  3992.                   "totals".
  3993.  
  3994.                o  Added cylindrical blob components.  Changed the syntax
  3995.                   for blobs to accommodate the new type.
  3996.  
  3997.                o  Added lathe surfaces made from either line segments or
  3998.                   quadratic splines.
  3999.  
  4000.                o  Added sweep surfaces made from quadratic splines.
  4001.  
  4002.                o  Height field syntax changed slightly.  Non-square height
  4003.                   fields now handled correctly.
  4004.  
  4005.                o  Added adaptive antialiasing.
  4006.  
  4007.                o  Squashed bug in shading routines that affected almost all
  4008.  
  4009.                                                                              74
  4010.  
  4011.  
  4012.                   primitives. This bug was most noticeable for objects
  4013.                   that were scaled using different values for x, y, and z.
  4014.  
  4015.                o  Added transparency values to color maps.
  4016.  
  4017.                o  Added new keywords to the file "polyray.ini":
  4018.                   shadow_tolerance, antialias, alias_threshold,
  4019.                   max_samples.  Lines that begin with "// " in polyray.ini
  4020.                   are now treated as comments.
  4021.  
  4022.                o  Short document called "texture.txt" is now included in
  4023.                   "plydoc.zip".  This describes in a little more detail
  4024.                   how to go about developing solid textures using Polyray.
  4025.  
  4026.                o  Added command line argument "-z start_line".  This allows
  4027.                   the user to start a trace somewhere in the middle of an
  4028.                   image.  Note that an image that was started this way
  4029.                   cannot be correctly resumed & completed.  (You may be
  4030.                   able to use image cut and paste utilities though.)
  4031.  
  4032.  
  4033.           Version 1.3
  4034.           (not released)
  4035.  
  4036.                o  Added support for scan converting implicit functions and
  4037.                   polynomial surfaces using the marching cubes algorithm.
  4038.                   This technique can be slow, and is restricted to objects
  4039.                   that have user defined bounding shapes, but now Polyray
  4040.                   is able to scan convert any primitive.
  4041.  
  4042.                o  A global shading flag has been added in order to
  4043.                   selectively turn on/off some of the more time consuming
  4044.                   shading options.  This option will also allow for the
  4045.                   use of raytracing as a way of determining shadows,
  4046.                   reflectivity, and transparency during scan conversion.
  4047.  
  4048.                o  Added new keywords to the file "polyray.ini": pixel_size,
  4049.                   pixel_encoding, shade_flags.
  4050.  
  4051.                o  Improved refraction code to (mostly) handle transparent
  4052.                   surfaces that are defined by CSG intersection.
  4053.  
  4054.                o  Fixed discoloring of shadows that receive some light
  4055.                   through a transparent object.
  4056.  
  4057.                o  Jittered antialiasing was not being called when the
  4058.                   option was selected, this has been fixed.
  4059.  
  4060.                o  Fixed parsing of blobs and polygons that had large
  4061.                   numbers of entries. Previously the parser would fail
  4062.  
  4063.                                                                              75
  4064.  
  4065.  
  4066.                   after 50-60 elements in a blob and the same number of
  4067.                   vertices of a polygon.
  4068.  
  4069.                o  In keeping with the format used by POV-Ray and Vivid,
  4070.                   comments may now start with "//" as well as "#".  The
  4071.                   use of the pound symbol for comments may be phased out
  4072.                   in future versions.
  4073.  
  4074.  
  4075.           Version 1.2
  4076.           Released: 16 February 1992
  4077.  
  4078.                o  Scan conversion of many primitives, using Z-Buffer
  4079.                   techniques.
  4080.  
  4081.                o  New primitives: sweep surface, torus
  4082.  
  4083.                o  Support for the standard 320x200 VGA display in 256
  4084.                   colors.
  4085.  
  4086.                o  An initialization file ("polyray.ini") is read before
  4087.                   processing.  This allows greater flexibility in tuning
  4088.                   many of the default values used by Polyray.
  4089.  
  4090.                o  User defined bounding slabs added.  This greatly improves
  4091.                   speed of rendering on data files with many small
  4092.                   objects.
  4093.  
  4094.                o  Noise surface added.
  4095.  
  4096.                o  Symbol table routines completely reworked.  Improved
  4097.                   speed for data files containing many definitions.
  4098.  
  4099.                o  Bug in the texturing of height fields corrected.
  4100.  
  4101.  
  4102.           Version 1.1
  4103.           (not released)
  4104.  
  4105.                o  Added parabola primitive
  4106.  
  4107.                o  Dithering of rays, and objects
  4108.  
  4109.                o  Blob code improved, shading corrected, intersection code
  4110.                   is faster and returns fewer incorrect results.
  4111.  
  4112.  
  4113.           Version 1.0
  4114.           Released: 27 December 1991
  4115.  
  4116.  
  4117.                                                                              76
  4118.  
  4119.  
  4120.                o  Several changes in input syntax were made, the most
  4121.                   notable result being that commas are required in many
  4122.                   more places.  The reason for this is that due to the
  4123.                   very flexible nature of expressions possible, a certain
  4124.                   amount of syntactic sugar is required to remove
  4125.                   ambiguities from the parser.
  4126.  
  4127.                o  Several new primitives were added: boxes, cones,
  4128.                   cylinders, discs, height fields, and Bezier patches.
  4129.  
  4130.                o  A new way of doing textures was added - each component of
  4131.                   the lighting model can be specified by an implicit
  4132.                   function that is evaluated at run time.  Using this
  4133.                   feature leads to slower textures, however because the
  4134.                   textures are defined in the data file instead of within
  4135.                   Polyray, development of mathematical texturing can be
  4136.                   developed without making alterations to Polyray.
  4137.  
  4138.                o  File flush commands in the data file and at the command
  4139.                   line were added.
  4140.  
  4141.                o  Several new Targa variants were added.
  4142.  
  4143.                o  Image mapping added.
  4144.  
  4145.                o  Numerous bug fixes have occurred.
  4146.  
  4147.  
  4148.           Version 0.3 (beta)
  4149.           Released: 14 October 1991
  4150.  
  4151.                o  This release added Constructive Solid Geometry,
  4152.                   functional surfaces defined in terms of transcendental
  4153.                   functions, a checker texture, and compressed Targa
  4154.                   output.
  4155.  
  4156.                o  Polyray no longer accepted a list of bounding/clipping
  4157.                   objects, only a single object is allowed. since CSG can
  4158.                   be used to define complex shapes, this is not a
  4159.                   limitation, and even better makes for cleaner data
  4160.                   files.
  4161.  
  4162.  
  4163.           Version 0.2 (beta)
  4164.           (not released)
  4165.  
  4166.                o  This release added animation support, defined objects,
  4167.                   arithmetic expression parsing, and blobs.
  4168.  
  4169.  
  4170.  
  4171.                                                                              77
  4172.  
  4173.  
  4174.           Version 0.1 (beta)
  4175.           (not released)
  4176.  
  4177.                o  First incarnation of Polyray.  This version had code for
  4178.                   polynomial equations and some of the basic surface types
  4179.                   contained in "mtv".
  4180.  
  4181.  
  4182.           7 Bibliography
  4183.  
  4184.                 "Introduction to Ray Tracing"
  4185.                 Edited by Andrew Glassner
  4186.                 Academic Press, 1989
  4187.  
  4188.                 "Illumination and Color in Computer Generated Imagery"
  4189.                 Roy Hall
  4190.                 Springer Verlag, 1989
  4191.  
  4192.                 "Numerical Recipes in C"
  4193.                 Press, et al.
  4194.                 Cambridge University Press, 1988
  4195.  
  4196.                 "CRC Handbook of Mathematical Curves and Surfaces"
  4197.                 David H. von Seggern
  4198.                 CRC Press, 1990
  4199.  
  4200.                 "Robust Ray Intersection with Interval Arithmetic"
  4201.                 D.P. Mitchell,
  4202.                 from:
  4203.                    "Proceedings Graphics Interface '90"
  4204.                    Canadian Information Processing Society
  4205.  
  4206.           8 Sample files
  4207.  
  4208.           A number of sample files are referenced in this document.  These
  4209.           files are contained in a separate archive, and demonstrate
  4210.           various features of Polyray.
  4211.  
  4212.           Simple demo files:
  4213.  
  4214.                boxes.pi           cone.pi      cossph.pi     cwheel.pi
  4215.             cylinder.pi           disc.pi     gsphere.pi     sphere.pi
  4216.                spot0.pi
  4217.  
  4218.           Sample color/texture definitions:
  4219.  
  4220.               colors.inc      textures.inc
  4221.  
  4222.           Polynomial surfaces:
  4223.  
  4224.  
  4225.                                                                              78
  4226.  
  4227.  
  4228.               bicorn.pi        bifolia.pi     cassini.pi      csaddle.pi
  4229.                devil.pi         folium.pi       helix.pi     hyptorus.pi
  4230.              kampyle.pi       lemnisca.pi        loop.pi       monkey.pi
  4231.              parabol.pi       partorus.pi    piriform.pi       qparab.pi
  4232.              qsaddle.pi        quarcyl.pi    quarpara.pi      steiner.pi
  4233.             strophid.pi         tcubic.pi       tear5.pi        torus.pi
  4234.               trough.pi       twincone.pi    twinglob.pi        witch.pi
  4235.  
  4236.           Implicit function surfaces
  4237.  
  4238.              sectorl.pi       sombrero.pi     sinsurf.pi       superq.pi
  4239.                zonal.pi
  4240.  
  4241.           Bezier patches
  4242.  
  4243.              bezier0.pi         teapot.pi      teapot.inc
  4244.  
  4245.           Height Fields
  4246.  
  4247.               hfnoise.pi        sombfn.pi       sinfn.pi        wake.pi
  4248.  
  4249.           Image mapping
  4250.  
  4251.                 map1.pi
  4252.  
  4253.           Texturing, CSG, etc.
  4254.  
  4255.                 lens.pi       lookpond.pi      marble.pi     polytope.pi
  4256.                spot1.pi           wood.pi      xander.pi
  4257.  
  4258.           Data file generators:
  4259.  
  4260.                balls.c            coil.c        gears.c       hilbert.c
  4261.             mountain.c         sphcoil.c        tetra.c
  4262.  
  4263.           Animation files:
  4264.  
  4265.                 plane.pi        squish.pi       whirl.pi
  4266.  
  4267.           9 Polyray Grammar
  4268.  
  4269.           What follows is the complete YACC grammar used to parse Polyray
  4270.           input files. Only the actions taken at each rule have been
  4271.           deleted.  The conventions used in the grammar are: keywords
  4272.           (terminal symbols like "sphere") appear in all caps, i.e. SPHERE.
  4273.           All other grammar rules (nonterminals) appear in lower case.  The
  4274.           terminal symbols, including punctuation, are either recognized by
  4275.           the lexical analyzer or by lookup from one of the symbol tables.
  4276.           (Note there is one ambiguity present in the grammar - the "if ..
  4277.           if .. else" construct.)
  4278.  
  4279.                                                                              79
  4280.  
  4281.  
  4282.  
  4283.           scene
  4284.              : elementlist
  4285.              ;
  4286.  
  4287.           elementlist
  4288.              : elementlist element
  4289.              | element
  4290.              ;
  4291.  
  4292.           element
  4293.              : background
  4294.              | camera
  4295.              | definition
  4296.              | flush_statement
  4297.              | frame_decl
  4298.              | if_statement
  4299.              | light
  4300.              | object
  4301.              | outfile
  4302.              | system_call
  4303.              ;
  4304.  
  4305.           defined_token
  4306.              : SURFACE_SYM
  4307.              | TEXTURE_SYM
  4308.              | OBJECT_SYM
  4309.              | EXPRESSION_SYM
  4310.              | TRANSFORM_SYM
  4311.              ;
  4312.  
  4313.           definition
  4314.              : DEFINE defined_token surface
  4315.              | DEFINE defined_token texture
  4316.              | DEFINE defined_token object
  4317.              | DEFINE defined_token transform
  4318.              | DEFINE defined_token expression
  4319.              | DEFINE TOKEN surface
  4320.              | DEFINE TOKEN texture
  4321.              | DEFINE TOKEN object
  4322.              | DEFINE TOKEN transform
  4323.              | DEFINE TOKEN expression
  4324.              ;
  4325.  
  4326.           object
  4327.              : OBJECT '{' object_decls '}'
  4328.              | OBJECT_SYM
  4329.              | OBJECT_SYM '{' object_modifier_decls '}'
  4330.              ;
  4331.  
  4332.  
  4333.                                                                              80
  4334.  
  4335.  
  4336.           object_modifier_decls
  4337.              : object_modifier_decl object_modifier_decls
  4338.              | object_modifier_decl
  4339.              ;
  4340.  
  4341.           object_modifier_decl
  4342.              : texture
  4343.              | transform
  4344.              | DITHER fexper
  4345.              | ROTATE point
  4346.              | ROTATE point ',' fexper
  4347.              | SHEAR fexper ',' fexper ',' fexper ',' fexper ','
  4348.                      fexper ',' fexper
  4349.              | TRANSLATE point
  4350.              | SCALE point
  4351.              | U_STEPS fexper
  4352.              | V_STEPS fexper
  4353.              | SHADING_FLAGS fexper
  4354.              | BOUNDING_BOX point ',' point
  4355.              | ROOT_SOLVER FERRARI
  4356.              | ROOT_SOLVER VIETA
  4357.              | ROOT_SOLVER STURM
  4358.              ;
  4359.  
  4360.           object_decls
  4361.              : shape_decl
  4362.              | shape_decl object_modifier_decls
  4363.              ;
  4364.  
  4365.           shape_decl
  4366.              : bezier
  4367.              | blob
  4368.              | box
  4369.              | cone
  4370.              | cylinder
  4371.              | csg
  4372.              | disc
  4373.              | function
  4374.              | gridded
  4375.              | height_field
  4376.              | height_fn
  4377.              | lathe
  4378.              | parabola
  4379.              | polygon
  4380.              | polynomial
  4381.              | ppatch
  4382.              | smooth_height_field
  4383.              | smooth_height_fn
  4384.              | sphere
  4385.              | sweep
  4386.  
  4387.                                                                              81
  4388.  
  4389.  
  4390.              | torus
  4391.              ;
  4392.  
  4393.           camera_exper
  4394.              : ANGLE fexper
  4395.              | APERTURE fexper
  4396.              | AT point
  4397.              | ASPECT fexper
  4398.              | MAX_TRACE_DEPTH fexper
  4399.              | DITHER_RAYS fexper
  4400.              | DITHER_OBJECTS fexper
  4401.              | FOCAL_DISTANCE fexper
  4402.              | FROM point
  4403.              | HITHER fexper
  4404.              | YON fexper
  4405.              | RESOLUTION fexper ',' fexper
  4406.              | UP point
  4407.              ;
  4408.  
  4409.           camera_expers
  4410.              : camera_expers camera_exper
  4411.              | camera_exper
  4412.              ;
  4413.  
  4414.           camera
  4415.              : VIEWPOINT '{' camera_expers '}'
  4416.              ;
  4417.  
  4418.           light_modifier_decl
  4419.              : COLOR expression
  4420.              | transform
  4421.              | ROTATE point
  4422.              | ROTATE point ',' fexper
  4423.              | SHEAR fexper ',' fexper ',' fexper ',' fexper ','
  4424.                      fexper ',' fexper
  4425.              | TRANSLATE point
  4426.              | SCALE point
  4427.              ;
  4428.  
  4429.           light_modifier_decls
  4430.              : light_modifier_decl light_modifier_decls
  4431.              |
  4432.              ;
  4433.  
  4434.           light
  4435.              : LIGHT point ',' point
  4436.              | LIGHT point
  4437.              | SPOT_LIGHT point ',' point
  4438.              | SPOT_LIGHT point ',' point ',' point ',' fexper ','
  4439.                           fexper ',' fexper
  4440.  
  4441.                                                                              82
  4442.  
  4443.  
  4444.              | TEXTURED_LIGHT '{' light_modifier_decls '}'
  4445.              ;
  4446.  
  4447.           background
  4448.              : BACKGROUND expression
  4449.              ;
  4450.  
  4451.           surface_declaration
  4452.              : COLOR expression
  4453.              | COLOR_MAP '(' map_entries ',' expression ')'
  4454.              | COLOR_MAP '(' map_entries ')'
  4455.              | AMBIENT expression ',' expression
  4456.              | AMBIENT expression
  4457.              | BUMP_SCALE expression
  4458.              | DIFFUSE expression ',' expression
  4459.              | DIFFUSE expression
  4460.              | FREQUENCY expression
  4461.              | LOOKUP_FUNCTION expression
  4462.              | MICROFACET PHONG expression
  4463.              | MICROFACET BLINN expression
  4464.              | MICROFACET GAUSSIAN expression
  4465.              | MICROFACET REITZ expression
  4466.              | MICROFACET COOK expression
  4467.              | MICROFACET expression
  4468.              | NORMAL expression
  4469.              | OCTAVES expression
  4470.              | PHASE expression
  4471.              | POSITION_FUNCTION expression
  4472.              | POSITION_SCALE expression
  4473.              | REFLECTION expression ',' expression
  4474.              | REFLECTION expression
  4475.              | SPECULAR expression ',' expression
  4476.              | SPECULAR expression
  4477.              | TRANSMISSION expression ',' expression ',' expression
  4478.              | TRANSMISSION expression ',' expression
  4479.              | TURBULENCE expression
  4480.              ;
  4481.  
  4482.           surface_declarations
  4483.              : surface_declaration surface_declarations
  4484.              |
  4485.              ;
  4486.  
  4487.           surface
  4488.              : SURFACE '{' surface_declarations '}'
  4489.              | SURFACE_SYM
  4490.              | SURFACE_SYM '{' surface_declarations '}'
  4491.              ;
  4492.  
  4493.           texture_modifier_decls
  4494.  
  4495.                                                                              83
  4496.  
  4497.  
  4498.              : texture_modifier_decl texture_modifier_decls
  4499.              | texture_modifier_decl
  4500.              ;
  4501.  
  4502.           texture_modifier_decl
  4503.              : transform
  4504.              | ROTATE point
  4505.              | ROTATE point ',' fexper
  4506.              | SHEAR fexper ',' fexper ',' fexper ',' fexper ','
  4507.                      fexper ',' fexper
  4508.              | TRANSLATE point
  4509.              | SCALE point
  4510.              ;
  4511.  
  4512.           texture_declarations
  4513.              : texture_declaration texture_modifier_decls
  4514.              | texture_declaration
  4515.              ;
  4516.  
  4517.           texture_declaration
  4518.              : surface
  4519.              | SPECIAL surface
  4520.              | NOISE surface
  4521.              | CHECKER texture ',' texture
  4522.              | HEXAGON texture ',' texture ',' texture
  4523.              | LAYERED texture_list
  4524.              ;
  4525.  
  4526.           texture
  4527.              : TEXTURE '{' texture_declarations '}'
  4528.              | TEXTURE_SYM
  4529.              | TEXTURE_SYM '{' texture_modifier_decls '}'
  4530.              ;
  4531.  
  4532.           texture_list
  4533.              : texture
  4534.              | texture_list ',' texture
  4535.              ;
  4536.  
  4537.           transform_declaration
  4538.              : ROTATE point
  4539.              | ROTATE point ',' fexper
  4540.              | SCALE point
  4541.              | TRANSLATE point
  4542.              ;
  4543.  
  4544.           transform_declarations
  4545.              : transform_declaration
  4546.              | transform_declarations transform_declaration
  4547.              ;
  4548.  
  4549.                                                                              84
  4550.  
  4551.  
  4552.  
  4553.           transform
  4554.              : TRANSFORM '{'
  4555.                transform_declarations '}'
  4556.              | TRANSFORM_SYM
  4557.              | TRANSFORM_SYM '{' transform_declarations '}'
  4558.              ;
  4559.  
  4560.           bezier_points
  4561.              : bezier_points ',' point
  4562.              | point
  4563.              ;
  4564.  
  4565.           bezier
  4566.              : BEZIER fexper ',' fexper ',' fexper ',' fexper ','
  4567.           bezier_points
  4568.              ;
  4569.  
  4570.           blob
  4571.              : BLOB fexper ':' blobelements
  4572.              ;
  4573.  
  4574.           blobelements
  4575.              : blobelement
  4576.              | blobelements ',' blobelement
  4577.              ;
  4578.  
  4579.           blobelement
  4580.              : fexper ',' fexper ',' point
  4581.              | SPHERE point ',' fexper ',' fexper
  4582.              | CYLINDER point ',' point ',' fexper ',' fexper
  4583.              | PLANE point ',' fexper ',' fexper ',' fexper
  4584.              | TORUS point ',' point ',' fexper ',' fexper ',' fexper
  4585.              ;
  4586.  
  4587.           box
  4588.              : BOX point ',' point
  4589.              ;
  4590.  
  4591.           cone
  4592.              : CONE point ',' fexper ',' point ',' fexper
  4593.              ;
  4594.  
  4595.           csg
  4596.              : csg_tree
  4597.              ;
  4598.  
  4599.           csg_tree
  4600.              : '(' csg_tree ')'
  4601.              | csg_tree '+' csg_tree
  4602.  
  4603.                                                                              85
  4604.  
  4605.  
  4606.              | csg_tree '-' csg_tree
  4607.              | csg_tree '*' csg_tree
  4608.              | '~' csg_tree
  4609.              | csg_tree '&' csg_tree
  4610.              | object
  4611.              ;
  4612.  
  4613.           cylinder
  4614.              : CYLINDER point ',' point ',' fexper
  4615.              ;
  4616.  
  4617.           disc
  4618.              : DISC point ',' point ',' fexper
  4619.              | DISC point ',' point ',' fexper ',' fexper
  4620.              ;
  4621.  
  4622.           function
  4623.              : FUNCTION expression
  4624.              ;
  4625.  
  4626.           gridded
  4627.              : GRIDDED sexper ',' object_list
  4628.              ;
  4629.  
  4630.           object_list
  4631.              : object
  4632.              | object object_list
  4633.              ;
  4634.  
  4635.           height_field
  4636.              : HEIGHT_FIELD sexper
  4637.              ;
  4638.  
  4639.           height_fn
  4640.              : HEIGHT_FN fexper ',' fexper ','
  4641.                          fexper ',' fexper ',' fexper ',' fexper ','
  4642.                          expression
  4643.              | HEIGHT_FN fexper ',' fexper ',' expression
  4644.              ;
  4645.  
  4646.           lathe
  4647.              : LATHE fexper ',' point ',' fexper  ',' pointlist
  4648.              ;
  4649.  
  4650.           parabola
  4651.              : PARABOLA point ',' point ',' fexper
  4652.              ;
  4653.  
  4654.           polygon:
  4655.              POLYGON fexper  ',' pointlist
  4656.  
  4657.                                                                              86
  4658.  
  4659.  
  4660.              ;
  4661.  
  4662.           polynomial
  4663.              : POLYNOMIAL expression
  4664.              ;
  4665.  
  4666.           ppatch
  4667.              : PATCH point ',' point ',' point ',' point ',' point ','
  4668.           point
  4669.              ;
  4670.  
  4671.           smooth_height_field
  4672.              : SMOOTH_HEIGHT_FIELD sexper
  4673.              ;
  4674.  
  4675.           smooth_height_fn
  4676.              : SMOOTH_HEIGHT_FN fexper ',' fexper ','
  4677.                          fexper ',' fexper ',' fexper ',' fexper ','
  4678.                          expression
  4679.              | SMOOTH_HEIGHT_FN fexper ',' fexper ',' expression
  4680.              ;
  4681.  
  4682.           sphere
  4683.              : SPHERE point ',' fexper
  4684.              ;
  4685.  
  4686.           sweep
  4687.              : SWEEP fexper ',' point ',' fexper  ',' pointlist
  4688.              ;
  4689.  
  4690.           torus
  4691.              : TORUS fexper ',' fexper ',' point ',' point
  4692.              ;
  4693.  
  4694.           fexper
  4695.              : expression
  4696.              ;
  4697.  
  4698.           point
  4699.              : expression
  4700.              ;
  4701.  
  4702.           sexper
  4703.              : expression
  4704.              ;
  4705.  
  4706.           pointlist
  4707.              : point
  4708.              | pointlist ',' point
  4709.              ;
  4710.  
  4711.                                                                              87
  4712.  
  4713.  
  4714.  
  4715.           expression
  4716.              : '(' expression ')'
  4717.              | '[' expression_list ']'
  4718.              | '<' expression ',' expression '>'
  4719.              | '<' expression ',' expression ',' expression '>'
  4720.              | expression '[' expression ']'
  4721.              | '(' conditional '?' expression ':' expression ')'
  4722.              | expression '^' expression
  4723.              | expression '%' expression
  4724.              | expression '*' expression
  4725.              | expression '.' expression
  4726.              | expression '/' expression
  4727.              | expression '+' expression
  4728.              | expression '-' expression
  4729.              | '-' expression %prec UMINUS
  4730.              | '|' expression '|'
  4731.              | COLOR_MAP '(' map_entries ',' expression ')'
  4732.              | COLOR_MAP '(' map_entries ')'
  4733.              | NOISE '(' expression ')'
  4734.              | NOISE '(' expression ',' expression ')'
  4735.              | ROTATE '(' expression ',' expression ')'
  4736.              | ROTATE '(' expression ',' expression ',' expression ')'
  4737.              | END_FRAME
  4738.              | START_FRAME
  4739.              | TOTAL_FRAMES
  4740.              | TOKEN '(' expression_list ')'
  4741.              | TOKEN
  4742.              | NUM
  4743.              | STRING
  4744.              | EXPRESSION_SYM
  4745.              ;
  4746.  
  4747.           expression_list
  4748.              : expression
  4749.              | expression ',' expression_list
  4750.              ;
  4751.  
  4752.           conditional
  4753.              : '(' conditional ')'
  4754.              | expression '<' expression
  4755.              | expression '>' expression
  4756.              | expression LTEQ_SYM expression
  4757.              | expression GTEQ_SYM expression
  4758.              | expression EQUAL_SYM expression
  4759.              | conditional AND_SYM conditional
  4760.              | conditional OR_SYM conditional
  4761.              | '!' conditional
  4762.              ;
  4763.  
  4764.  
  4765.                                                                              88
  4766.  
  4767.  
  4768.           map_entry
  4769.              : '[' fexper ',' fexper ',' point ',' point ']'
  4770.              | '[' fexper ',' fexper ',' point ',' fexper ',' point ','
  4771.           fexper ']'
  4772.              ;
  4773.  
  4774.           map_entries
  4775.              : map_entry map_entries
  4776.              | map_entry
  4777.              ;
  4778.  
  4779.           frame_decl
  4780.              : end_frame_decl
  4781.              | start_frame_decl
  4782.              | total_frames_decl
  4783.              ;
  4784.  
  4785.           end_frame_decl
  4786.              : END_FRAME fexper
  4787.              ;
  4788.  
  4789.           start_frame_decl
  4790.              : START_FRAME fexper
  4791.              ;
  4792.  
  4793.           total_frames_decl
  4794.              : TOTAL_FRAMES fexper
  4795.              ;
  4796.  
  4797.           outfile
  4798.              : OUTFILE TOKEN
  4799.              | OUTFILE STRING
  4800.              ;
  4801.  
  4802.           flush_statement
  4803.              : FILE_FLUSH fexper
  4804.              ;
  4805.  
  4806.           system_call
  4807.              : SYSTEM '(' expression_list ')'
  4808.              ;
  4809.  
  4810.           statement
  4811.              : '{' elementlist '}'
  4812.              | element
  4813.              ;
  4814.  
  4815.           if_else_part
  4816.              : ELSE statement
  4817.              |
  4818.  
  4819.                                                                              89
  4820.  
  4821.  
  4822.              ;
  4823.  
  4824.           if_statement
  4825.              : IF '(' conditional ')' statement if_else_part
  4826.              ;
  4827.              ;
  4828.